Python unittests are broken with python 3.11 and pytest
Summary
Most of our pytest unittests are broken with Python 3.11. They depended on an undocumented private property that was removed in Python 3.11
Steps to reproduce
- Install Python 3.11
- Run
pytest
orninja test
What is the current bug behavior?
- Most of the tests fail with something like
def _last_test_failed(self):
"""Check for non-skipped tests that resulted in errors."""
# The test outcome is not available via the public unittest API, so
# check a private property, "_outcome", set by unittest.TestCase.run.
# It remains None when running in debug mode (`pytest --pdb`).
# The property is available since Python 3.4 until at least Python 3.7.
if self._outcome:
> for test_case, exc_info in self._outcome.errors:
E AttributeError: '_Outcome' object has no attribute 'errors'
- E.g., =========== 384 failed, 364 passed, 15 skipped, 15 errors in 21.73s
What is the expected correct behavior?
- Tests should pass.
See some other projects facing similar issues: https://github.com/sbmlteam/libsbml/issues/177 https://github.com/cockpit-project/cockpit/issues/17491 https://adamj.eu/tech/2022/11/14/unittest-context-methods-python-3-11-backports/