Skip to content

unittest: fix assertion errors on unittest reruns #12436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/12424.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash with `assert testcase is not None` assertion failure when re-running unittest tests using plugins like pytest-rerunfailures. Regressed in 8.2.2.
2 changes: 1 addition & 1 deletion src/_pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
self._explicit_tearDown()
self._explicit_tearDown = None
self._obj = None
self._instance = None
del self._instance

Check warning on line 225 in src/_pytest/unittest.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/unittest.py#L225

Added line #L225 was not covered by tests
super().teardown()

def startTest(self, testcase: "unittest.TestCase") -> None:
Expand Down
11 changes: 11 additions & 0 deletions testing/plugins_integration/pytest_rerunfailures_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unittest


class MyTestCase(unittest.TestCase):
first_time = True

def test_fail_the_first_time(self) -> None:
"""Regression test for issue #12424."""
if self.first_time:
type(self).first_time = False
self.fail()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ commands =
pytest --cov=. simple_integration.py
pytest --ds=django_settings simple_integration.py
pytest --html=simple.html simple_integration.py
pytest --reruns 5 simple_integration.py
pytest --reruns 5 simple_integration.py pytest_rerunfailures_integration.py
pytest pytest_anyio_integration.py
pytest pytest_asyncio_integration.py
pytest pytest_mock_integration.py
Expand Down
Loading