Skip to content

Conversation

@cricalix
Copy link
Contributor

@cricalix cricalix commented Mar 30, 2021

with assertRaises(Exception): is basically a "catch 'em all" assert that casts far too broad of a net when it comes to detecting failures in code being tested. Assertions should be testing specific failure cases, not "did Python throw /any/ type of error?", and so the context manager form, or the assertRaisesRegex form are far better to use.

With the implementation of this code, it is possible that someone would write with self.assertRaises(Exception) as ex: and then never check ex, but linters should then warn about the unused context variable.

W503 had to be ignored because test_selfclean_bugbear() was upset by the warnings being raised for the syntax in use, despite that syntax being the syntax created by the recommended formatter, black.

This kind of lint check can also be found in openstack/hacking as H202, but implementing that module for flake8 requires pulling in a lot of extras, and it's very opinionated about versions of the extras to import.

```with assertRaises(Exception):``` is basically a "catch 'em all" assert that casts far too broad of a net when it comes to detecting failures in code being tested. Assertions should be testing specific failure cases, not "did Python throw /any/ type of error?", and so the context manager form, or the assertRaisesRegex form are far better to use.
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Can you just:

  • Remove version change (who knows when I will release, but will be soon)
  • See if you can get rid of W503, if not no big deal
  • Fix the context manager raises whitespace

Then also

  • Add to README your explanation like other checks
    • Add this to "Change Log" in README too please

@cricalix cricalix removed their assignment Mar 31, 2021
@cricalix cricalix requested a review from cooperlees March 31, 2021 15:23
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me and ready to merge.

@cooperlees cooperlees merged commit 9d18e5f into PyCQA:master Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants