compliance-trestle icon indicating copy to clipboard operation
compliance-trestle copied to clipboard

tests with pytest.raises(Exception) should be made more specific

Open fsuits opened this issue 2 years ago • 1 comments

flake8-bugbear blocks the usage of pytest.raises(Exception) with warning B017 for many of the earlier test files. The purpose for the warning is that the reason for failure could simply be that the code did not run - as opposed to following the expected code path leading to the exception. So it's important to have a more specific assert that confirms the expected type of failure did happen.

This is only an issue for tests, and examination finds it applies mainly to earlier tests. It will take some examination of each test to give it a more specific assert condition - so for now the B017 warning is disabled in pre-commit. But it would be good to fix the tests since they may have been failing for the wrong reason all this time.

fsuits avatar Jan 18 '23 04:01 fsuits