`pytest -k` should ignore private attributes (starting with `_`)
See original GitHub issueI 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:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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)
Created #7546 to track this.