-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-136442: Fix unittest to return exit code 5 when setUpClass raises an exception #136487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check "ERROR: setUpClass" and "SetUpClassFailure" here. Otherwise I think it's good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks!
|
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 <[email protected]>
|
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 <[email protected]>
|
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