Skip to content

Commit f85289b

Browse files
authored
Merge pull request #12436 from bluetech/unittest-rerun-assertion
unittest: fix assertion errors on unittest reruns
2 parents 18f15a3 + de47b73 commit f85289b

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

changelog/12424.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

src/_pytest/unittest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def teardown(self) -> None:
223223
self._explicit_tearDown()
224224
self._explicit_tearDown = None
225225
self._obj = None
226-
self._instance = None
226+
del self._instance
227227
super().teardown()
228228

229229
def startTest(self, testcase: "unittest.TestCase") -> None:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import unittest
2+
3+
4+
class MyTestCase(unittest.TestCase):
5+
first_time = True
6+
7+
def test_fail_the_first_time(self) -> None:
8+
"""Regression test for issue #12424."""
9+
if self.first_time:
10+
type(self).first_time = False
11+
self.fail()

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ commands =
141141
pytest --cov=. simple_integration.py
142142
pytest --ds=django_settings simple_integration.py
143143
pytest --html=simple.html simple_integration.py
144-
pytest --reruns 5 simple_integration.py
144+
pytest --reruns 5 simple_integration.py pytest_rerunfailures_integration.py
145145
pytest pytest_anyio_integration.py
146146
pytest pytest_asyncio_integration.py
147147
pytest pytest_mock_integration.py

0 commit comments

Comments
 (0)