Skip to content

Commit

Permalink
Handle breaking api change in Python 3.12.1
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
mtreinish authored and stephenfin committed Jan 16, 2024
1 parent 50075c2 commit a481b55
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions testtools/testresult/real.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def startTest(self, test):
self._tags = TagContext(self._tags)

def stopTest(self, test):
self._tags = self._tags.parent
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
if self._tags is not None:
self._tags = self._tags.parent
super().stopTest(test)

@property
Expand Down Expand Up @@ -1608,7 +1610,9 @@ def stop(self):
self.shouldStop = True

def stopTest(self, test):
self._tags = self._tags.parent
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
if self._tags is not None:
self._tags = self._tags.parent
return self.decorated.stopTest(test)

def stopTestRun(self):
Expand Down Expand Up @@ -1670,7 +1674,9 @@ def startTest(self, test):
self._tags = TagContext(self._tags)

def stopTest(self, test):
self._tags = self._tags.parent
# NOTE: In Python 3.12.1 skipped tests may not call startTest()
if self._tags is not None:
self._tags = self._tags.parent

def addError(self, test, err=None, details=None):
self._check_args(err, details)
Expand Down

0 comments on commit a481b55

Please sign in to comment.