pytest has built-in support for rather detailed assert messages. Allowing the testwriter to just use plain asserts:
instead of
if 1 == 2:
raise check50.Failure("1 does not equal 2")
To do this pytest rewrites part of the code and as it turns out that functionality is reasonably separate from pytests' core. With inspiration from their own test suite:
echo "assert 1 == 2" > bar.py
import ast
from _pytest.assertion.rewrite import rewrite_asserts
def rewrite(src: str) -> ast.Module:
tree = ast.parse(src)
rewrite_asserts(tree, src.encode())
return tree
src = open("bar.py").read()
mod = rewrite(src)
code = compile(mod, "<test>", "exec")
namespace = {}
exec(code, namespace)
Just a thought, but perhaps it's worth exploring?
pytest has built-in support for rather detailed
assertmessages. Allowing the testwriter to just use plainasserts:instead of
To do this pytest rewrites part of the code and as it turns out that functionality is reasonably separate from pytests' core. With inspiration from their own test suite:
Just a thought, but perhaps it's worth exploring?