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

pytest -k should ignore private attributes (starting with _) #7539

Open
asmeurer opened this issue Jul 24, 2020 · 5 comments
Open

pytest -k should ignore private attributes (starting with _) #7539

asmeurer opened this issue Jul 24, 2020 · 5 comments
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@asmeurer
Copy link

I originally opened this issue in hypothesis, but they told me to open it here HypothesisWorks/hypothesis#2508.

When I run pytest -k name, and name only matches hypothesis tests, pytest runs all hypothesis tests, not just the ones that match. When name matches a non-hypothesis test, it only picks the tests that contain name as expected.

I am using pytest 5.4.3 and hypothesis 5.21.0. It happens even when I set aside my pytest.ini and conftest.py.

You can reproduce this at the repo https://github.com/Quansight/ndindex/ by running pytest -v -k repr.

@asottile
Copy link
Member

hypothesis is attaching additional attributes to the test function which is triggering this:

{'is_hypothesis_test', '_hypothesis_internal_use_settings', 'test_ellipsis.py', 'hypothesis', '_hypothesis_internal_use_reproduce_failure', '_hypothesis_internal_use_seed', 'tests', 'test_ellipsis_hypothesis'}

repr is matching _hypothesis_internal_use_reproduce_failure

@asmeurer
Copy link
Author

Is there a way to make -k only match function names? I don't care about that other stuff.

@nicoddemus
Copy link
Member

Hi @asmeurer, I'm afraid not at the moment with the -k flag, it always matches partially against node names and "keywords".

@asottile
Copy link
Member

this behaviour has existed since pytest 2.4.0 but as far as I can tell is undocumented (and wasn't called out in the changelog)

I think at least this should be documented and improved to avoid underscored names (this would solve this particular issue, but I think would be a reasonable baseline expectation)

@nicoddemus
Copy link
Member

I think at least this should be documented

Created #7546 to track this.

@Zac-HD Zac-HD changed the title pytest -k is picking all hypothesis tests pytest -k should ignore private attributes (starting with _) Aug 11, 2020
@Zac-HD Zac-HD added the type: enhancement new feature or API change, should be merged into features branch label Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants