gh-136442: Fix unittest to return exit code 5 when setUpClass raises an exception#136487
gh-136442: Fix unittest to return exit code 5 when setUpClass raises an exception#136487gaogaotiantian merged 8 commits intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
gaogaotiantian
left a comment
There was a problem hiding this comment.
Overall I think it's good, just a few minor suggestions.
| self.assertEqual(cm.exception.code, 1) | ||
| out = stream.getvalue() | ||
| self.assertIn('\nERROR: setUpClass (test.test_unittest.test_program.' | ||
| 'Test_TestProgram.SetUpClassFailure)\n', out) |
There was a problem hiding this comment.
I think the error message you are trying to catch here is a bit too specific. Part of the strings is related to how the testing infra is designed, we should not test those. I think the actual test case related info is SetUpClassFailure, setUpClass and probably ERROR, let's just write two assertIn for those info.
| self.assertEqual(result.testsRun, 2) | ||
| self.assertEqual(len(result.errors), 0) | ||
|
|
||
| def test_setup_class_raising_error(self): |
There was a problem hiding this comment.
Is this test case related to this issue? Seems like you are trying to test that an exception in setUpClass will stop the test? If it's not directly related, I think it's better to have the commit to include only related tests, so it's easier for us to follow the commit history.
Misc/NEWS.d/next/Tests/2025-07-09-21-45-51.gh-issue-136442.jlbklP.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @gaogaotiantian: please review the changes made to this pull request. |
| testLoader=self.TestLoader(self.SetUpClassFailure)) | ||
| self.assertEqual(cm.exception.code, 1) | ||
| out = stream.getvalue() | ||
| self.assertIn("ERROR", out) |
There was a problem hiding this comment.
Let's check "ERROR: setUpClass" and "SetUpClassFailure" here. Otherwise I think it's good!
|
Thanks @ueshin for the PR, and @gaogaotiantian for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…aises an exception (pythonGH-136487) (cherry picked from commit 53d65c8) Co-authored-by: Takuya UESHIN <ueshin@happy-camper.st>
|
GH-141576 is a backport of this pull request to the 3.14 branch. |
…aises an exception (pythonGH-136487) (cherry picked from commit 53d65c8) Co-authored-by: Takuya UESHIN <ueshin@happy-camper.st>
|
GH-141577 is a backport of this pull request to the 3.13 branch. |
…aises an exception (python#136487)
Fixes
unittestto return exit code5whensetUpClassraises an exception.unittestmay incorrectly return exit code 5 whensetUpClassraises an exception #136442