Skip to content

Commit e95d993

Browse files
committed
Handle breaking api change in Python 3.12.1
In Python 3.12.1 python/cpython#106588 was backported which changed the execution behavior of the unittest runner. After python/cpython#106588 startTest() is no longer being called if a test is skipped. This causes knock-on effects in testtools because the test result subclasses were assuming that startTest() was always called when stopTest() was called. To handle this change in behavior when running with Python 3.12.1 this commit adds a check to only deal with tags if they exist (when startTest() is run).
1 parent 50075c2 commit e95d993

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

testtools/testresult/real.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ def startTest(self, test):
227227
self._tags = TagContext(self._tags)
228228

229229
def stopTest(self, test):
230-
self._tags = self._tags.parent
230+
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
231+
if self._tags is not None:
232+
self._tags = self._tags.parent
231233
super().stopTest(test)
232234

233235
@property
@@ -1608,7 +1610,9 @@ def stop(self):
16081610
self.shouldStop = True
16091611

16101612
def stopTest(self, test):
1611-
self._tags = self._tags.parent
1613+
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
1614+
if self._tags is not None:
1615+
self._tags = self._tags.parent
16121616
return self.decorated.stopTest(test)
16131617

16141618
def stopTestRun(self):
@@ -1670,7 +1674,9 @@ def startTest(self, test):
16701674
self._tags = TagContext(self._tags)
16711675

16721676
def stopTest(self, test):
1673-
self._tags = self._tags.parent
1677+
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
1678+
if self._tags is not None:
1679+
self._tags = self._tags.parent
16741680

16751681
def addError(self, test, err=None, details=None):
16761682
self._check_args(err, details)

0 commit comments

Comments
 (0)