Skip to content

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

Closed
@sobolevn

Description

@sobolevn

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

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions