Skip to content
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

Add else: fail() to test cases where exception is always expected #120544

Closed
sobolevn opened this issue Jun 15, 2024 · 0 comments
Closed

Add else: fail() to test cases where exception is always expected #120544

sobolevn opened this issue Jun 15, 2024 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Jun 15, 2024

Bug report

Most except self.failureClass cases have else branch where we can ensure that the exception really did happen:

try:
self.assertSequenceEqual(seq1, seq2)
except self.failureException as e:
msg = e.args[0]
else:
self.fail('assertSequenceEqual did not fail.')

But, some rare ones do not have them:

try:
self.assertMultiLineEqual(sample_text, revised_sample_text)
except self.failureException as e:
# need to remove the first line of the error message
error = str(e).split('\n', 1)[1]
self.assertEqual(sample_text_error, error)

So, in theory they can just succeed and except branch might never be called. This is a theorical problem, but it is still a problem.

I propose to add else branches to these tests, just to be safe.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jun 15, 2024
@sobolevn sobolevn self-assigned this Jun 15, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Jun 15, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Jun 15, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 15, 2024
…ted (pythonGH-120545)

(cherry picked from commit 42ebdd8)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 15, 2024
…ted (pythonGH-120545)

(cherry picked from commit 42ebdd8)

Co-authored-by: Nikita Sobolev <[email protected]>
AlexWaygood pushed a commit that referenced this issue Jun 15, 2024
…cted (GH-120545) (#120546)

gh-120544: Add `else: fail()` to tests where exception is expected (GH-120545)
(cherry picked from commit 42ebdd8)

Co-authored-by: Nikita Sobolev <[email protected]>
AlexWaygood pushed a commit that referenced this issue Jun 15, 2024
…cted (GH-120545) (#120547)

gh-120544: Add `else: fail()` to tests where exception is expected (GH-120545)
(cherry picked from commit 42ebdd8)

Co-authored-by: Nikita Sobolev <[email protected]>
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants