This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest.TestResult.addSubTest should be called immediately after subtest finishes
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, michael.foord, rbcollins, serhiy.storchaka, sir-sigurd
Priority: normal Keywords: patch

Created on 2017-07-05 13:56 by sir-sigurd, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_subtest.py sir-sigurd, 2017-07-05 13:56
Pull Requests
URL Status Linked Edit
PR 28180 merged serhiy.storchaka, 2021-09-05 18:42
Messages (3)
msg297756 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2017-07-05 13:56
Currently TestResult.addSubTest() is called just before TestResult.stopTest(), but docs says that addSubTest is "Called when a subtest finishes". IMO that means that it will be called immediately after subtest finishes, but not after indefinite time.

Test is attached.
msg401102 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-05 18:45
Before b3468f79efa45c8adaf86c0b9b797b9b3d4c12a2 the TestResult methods (addFailure, addError, addSkip, addExpectedFailure, addUnexpectedSuccess) were called immediately after running the test method. After that change all skips, failures and errors were accumulated separately and TestResult was updated only after the test cleanup. I do not know whether there were reasons for this or it is just an implementation artifact.

The proposed PR makes addFailure, addError, addSkip and addSubTest be called immediately after raising an exception or finishing a subtest. addExpectedFailure, addUnexpectedSuccess and addSuccess still need to wait the end of the test cleanup.
msg402153 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-09-19 12:24
New changeset 664448d81f41c5fa971d8523a71b0f19e76cc136 by Serhiy Storchaka in branch 'main':
bpo-30856: Update TestResult early, without buffering in _Outcome (GH-28180)
https://github.com/python/cpython/commit/664448d81f41c5fa971d8523a71b0f19e76cc136
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 75039
2021-09-19 12:25:04serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-09-19 12:24:44serhiy.storchakasetmessages: + msg402153
2021-09-05 18:45:39serhiy.storchakasetmessages: + msg401102
versions: + Python 3.11
2021-09-05 18:42:37serhiy.storchakasetkeywords: + patch
nosy: + serhiy.storchaka

pull_requests: + pull_request26606
stage: patch review
2017-07-08 03:02:54terry.reedysetnosy: + rbcollins, ezio.melotti, michael.foord
2017-07-06 05:37:49sir-sigurdsetcomponents: + Library (Lib)
2017-07-05 13:56:36sir-sigurdcreate