Repository navigation
TestResult.stopTest called when test is skipped, despite TestResult.startTest not being called #113267
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 19, 2023 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Dec 19, 2023 - changed the title
[-]`TestResult.stopTest` called when test is skipped, despite `TestResult.startTest`[/-][+]`TestResult.stopTest` called when test is skipped, despite `TestResult.startTest` not being called[/+]on Dec 19, 2023 I am now also seeing failures in PyCharm's unit testing because of this issue.
This is starting to be a huge issue.
I think that it was a wrong change, and not only because it makes
startTest()andstopTest()calls unbalanced, but because it did not handle all cases and changed the behavior in wrong direction. #113661 was the proper fix of the original problem.Thanks, the changes for 3.12.2 seem to fix CleanCut/green#277
- added a commit that references this issue
on Feb 27, 2024 - added a commit that references this issue
on Feb 28, 2024 - added 2 commits that reference this issue
on Feb 28, 2024
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
Following commit 551aa6ab9419109a80ad53900ad930e9b7f2e40d a bug seems to have been introduced in the
TestCase.runmethod.Because the
result.startTest(self)call was moved inside the try/finally block after the check to see if the test is skipped, theresult.stopTest(self)call will be made even if the test is skipped andstartTestis never called.While this does not cause issues with the standard
TestResultorTextTestResultclasses, it can cause issues with other classes which subclass those and expect every call tostopTestto be preceded by a call fromstartTest.Most notably for me, the
unittest-xml-reportingpackage, whosestopTestmethod uses data initialized instartTest.Note: Further thinking about this problem, it seems like changing the flow of methods like this was ill thought solution to the problem in the first place, as this might be an unexpected change of behaviour for different libraries. I'm still leaving what I think could be the solution in case I'm wrong on that.
It looks like the fix would seem to be moving the call to
stopTestin yet another try/finally block right after the call tostartTest, emulating the same behaviour as previous code while keeping the call tostartTestafter the skip check. The call tostopTestRunwould need to remain where it is asstartTestRunhas already been called at this point.So using the code as found in that commit, something like:
CPython versions tested on:
3.12
Operating systems tested on:
Linux, Windows
Linked PRs