question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I originally opened this issue in hypothesis, but they told me to open it here https://github.com/HypothesisWorks/hypothesis/issues/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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Jul 26, 2020

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)

0reactions
nicoddemuscommented, Jul 27, 2020

I think at least this should be documented

Created #7546 to track this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get pytest to ignore Test* classes that don't subclass ...
I found this in the Pytest 2.6 release notes: support nose-style __test__ attribute on modules, classes and functions, including unittest-style Classes.
Read more >
_pytest.config.argparsing — pytest documentation
The returned group object has an ``addoption`` method with the same signature as :func:`parser.addoption <pytest.Parser.addoption>` but will be shown in the ...
Read more >
test — Regression tests package for Python — Python 3.11.1 ...
By default this skips private attributes beginning with '_' but includes all magic methods, i.e. those starting and ending in '__'. New in...
Read more >
Python Private attributes and methods - YouTube
In this Python Tutorial for Beginners video I am going to show How to declare Private methods in Python. To create a private...
Read more >
How to avoid the need to Unit test private methods
You're partially right - you shouldn't directly test private methods. The private methods on a class should be invoked by one or more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found