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 B017 support for pytest.raises #317

Merged
merged 2 commits into from
Dec 11, 2022

Conversation

inwaves
Copy link
Contributor

@inwaves inwaves commented Dec 7, 2022

Hi! This PR should solve #169, where calls like with pytest.raises(Exception): are not being flagged by B017, even though they are basically the same use case as with self.assertRaises(Exception).

I'm uncertain about the best structure for tests/b017.py, and I'm open to suggestions here. For now, I've just added the analogous pytest.raises calls for each of the test cases with assertRaises.

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.

Thanks for this. This totally makes sense.

I'd just like to know how the pytest import is working? Does GitHub actions install it by default or something?

Also cc: @cricalix - Thoughts on this?

Comment on lines +8 to +9
import pytest

Copy link
Collaborator

Choose a reason for hiding this comment

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

This confuses me how this works as we don't have pytest named as a dependency anywhere ...

Should we add it to dependencies or the dev optional dependencies now too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Not sure how this is being found. Agreed on adding to dev optional dependencies, though it would be good to know where it's currently being taken from.

@cricalix
Copy link
Contributor

Thanks for this. This totally makes sense.

I'd just like to know how the pytest import is working? Does GitHub actions install it by default or something?

Also cc: @cricalix - Thoughts on this?

No objections your honour. Not sure there's a cleaner way to check the AST without spending a bunch of time fiddling with pytest and bugbear (and we know how that's gone before..). Couldn't see anything in GH actions that default installs pytest either, nor any reference to pytest in the bugbear repo (oh for buck cquery rdeps).

@cooperlees
Copy link
Collaborator

I'll happily not know here to avoid using buck.

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