pytest: Better API for assertion failure reprs
PyCharm injects a pytest plugin to enable the IDE to intercept comparison assertion failures and provide an integrated diff UI for them. Currently it does a bunch of messy things that fail in complex cases:
- implements
pytest_assertrepr_compareto encode the assertion failure in a more resilient way - overrides
config.option.verbose = 2to avoid truncation - picks up the results in
pytest_runtest_logreport - hackily undoes
_pytest.assertion.util.format_explanation
It’ll be nice to have a way for plugins to stash assertion failures in a more structured way so they could be “picked up” in pytest_runtest_logreport cleanly and then serialized in whatever way the IDE prefers to get them.
Currently:
pytest_assertrepr_comparegetsconfigbut notitemso there’s no way to stash structured results on theitempytest_assertrepr_comparereturn value is aOptional[List[str]](no complex data structure)
Open to other ideas of course.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (17 by maintainers)
We plan to eventually make
Node._storeavailable to users, but we don’t have a clear roadmap for that yet.You might as well just create your own attribute,
Node._pycharm_dataor something, plugins have been doing that for years to attach data toNodeandConfig.@ikonst would you like to contribute that?
in that case my concern is completely unwarranted ,lets add item in addition to config