Skip to content

Resolve new flake8 error #4462

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

Merged
merged 3 commits into from
Jan 19, 2023
Merged

Resolve new flake8 error #4462

merged 3 commits into from
Jan 19, 2023

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Jan 18, 2023

Description

Resolve this new failure:

PR #4461: https://results.pre-commit.ci/run/github/38581626/1674006122.PZIdTNh0SNa60OuNgaDU9w

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/test_modules.py:110:13: B017 assertRaises(Exception): or pytest.raises(Exception) should be considered evil. It can lead to your test passing even if the code being tested is never executed due to a typo. Either assert for a more specific exception (builtin or custom), use assertRaisesRegex, or use the context manager form of assertRaises.
            with pytest.raises(Exception):
            ^

For simplicity & safety, giving up on the idea to future-proof the test (see removed comment).

The danger pointed out by flake8 B017 is real, and currently all Python versions generate a SystemError.

Minor remarks for completeness:

  • To reproduce the new flake8 error locally I had to run pre-commit clean
  • The bugbear version is not pinned (see below), therefore this failure came as a surprise, unrelated to any changes in pybind11.

Suggested changelog entry:

@rwgk rwgk marked this pull request as ready for review January 18, 2023 05:13
@rwgk rwgk requested review from Skylion007 and henryiii January 18, 2023 05:13
@henryiii
Copy link
Collaborator

It's a flake8-bugbear bump, I expect. You'll need to clear your pre-commit cache locally to see it, as we don't pin bugbear.

@henryiii
Copy link
Collaborator

Is there a reason to remove the comment? That seems helpful to both explain why there's an expected exception, as well as if it ever does change, we'd know to just add the new failure there too.

@rwgk rwgk force-pushed the flake8_raises_exception branch from cf184f3 to f87da1b Compare January 18, 2023 21:59
@rwgk
Copy link
Collaborator Author

rwgk commented Jan 18, 2023

Is there a reason to remove the comment? That seems helpful to both explain why there's an expected exception, as well as if it ever does change, we'd know to just add the new failure there too.

I wasn't sure, tweak or remove. After seeing your feedback I tweaked now instead of removing. What do you think?

@rwgk
Copy link
Collaborator Author

rwgk commented Jan 18, 2023

It's a flake8-bugbear bump, I expect. You'll need to clear your pre-commit cache locally to see it,

Thanks for the hint! Confirmed, after pre-commit clean I'm seeing the error locally. (I never knew about this before.)

as we don't pin bugbear.

Could we pin bugbear? Getting surprised in the middle of something else can be quite distracting.

@Skylion007
Copy link
Collaborator

@rwgk Upgrading just becomes a bit annoying since we don't have any autoupdate functionality for pinned additional_dependencies.

@rwgk
Copy link
Collaborator Author

rwgk commented Jan 19, 2023

@rwgk Upgrading just becomes a bit annoying since we don't have any autoupdate functionality for pinned additional_dependencies.

Thanks! In that case I think not pinning is fine. Next time I'll be less surprised :-)

Does the changed comment look good to you?

@Skylion007
Copy link
Collaborator

Yeah, looks good.

@rwgk rwgk merged commit a500f43 into pybind:master Jan 19, 2023
@rwgk rwgk deleted the flake8_raises_exception branch January 19, 2023 18:48
@rwgk
Copy link
Collaborator Author

rwgk commented Jan 19, 2023

Thanks!

@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jan 19, 2023
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Jan 19, 2023
henryiii pushed a commit that referenced this pull request Feb 24, 2023
* Resolve flake8 error by replacing `pytest.raises(Exception)` with `SystemError`

* Also remove the obsolete comment.

* Tweak comment instead of removing it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants