3 ms·
> Of course, this technique only works in dynamic languages. Actually, pytest does that by rewriting the AST[0], basically it rewrites the `assert` statement i
by 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-...