3 ms·
Wow... I am using Django's stock test runner and that makes me jealous. I've wished I could just write python asserts and have it print useful information. Of
by jchw 9y ago
Wow... I am using Django's stock test runner and that makes me jealous. I've wished I could just write python asserts and have it print useful information.
Of course, this technique only works in dynamic languages. In Go I use testify assert and that is good enough for me.
- louthy 9y ago> Of course, this technique only works in dynamic language It can work in any language that supports reflection, dynamic or not.
- nothrabannosir 9y agoOr macros, or just direct language (i.e. compiler) support.
- masklinn 9y ago> Of course, this technique only works in dynamic languages. Actually, pytest does that by rewriting the AST[0], basically it rewrites the `assert` statement into a more complex form which extracts all the info it needs upon failure. In a statically typed language, you could do that with a compilation hook and some codegen. There used to be a "reinterpret" mode where it would walk the stack frame and try to understand the expression involved at runtime, that was removed in Pytest 3.0, now the choices are assert-rewriting and plain assert (without any introspection). [0] http://pybites.blogspot.be/2011/07/behind-scenes-of-pytests-new-assertion.html http://pybites.blogspot.be/2011/07/behind-scenes-of-pytests-...
- akx 9y agoJust switch to pytest + pytest-django. It can run Django tests.