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 8.0.0 now collects all files in current directory even if you specify test files #11974

Closed
sshane opened this issue Feb 14, 2024 · 1 comment

Comments

@sshane
Copy link

sshane commented Feb 14, 2024

After 385796b, pytest sends all files in the current directory to every plugin's pytest_collect_file hook, even if you are only wanting to run/collect tests from one file. If you have pytest-cpp installed, it means it executes all executable files in the current directory, which isn't desired behavior at all, or at least unexpected.

safety/
  test_toyota.py
  test_coverage.sh  # shouldn't be run

pytest test_toyota.py -> runs test_coverage.sh (which in my case is long running and runs another pytest causing a recursive loop)

Now, this isn't because of pytest per se, but the pytest-cpp plugin which runs all executable files with --help to discover if it's a certain test suite file. If this new behavior of collecting every file, despite specifying your file filter is intentional, we can close this.


A worse case is just:

safety/
  test_toyota.py
  test.sh

where test.sh has a pytest command inside it with some extra setup:

pytest -n auto test_*.py -k 'not Base'

currently, it will recursively run itself with pytest-cpp installed.

@sshane sshane changed the title pytest now runs all executable files in directory of test file pytest now collects all files in current directory even if you specify test files Feb 14, 2024
@sshane sshane changed the title pytest now collects all files in current directory even if you specify test files pytest 8.0.0 now collects all files in current directory even if you specify test files Feb 14, 2024
@bluetech
Copy link
Member

This is something I am planning to fix for the 8.1.x timeframe. Closing as duplicate of #11904.

@bluetech bluetech closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
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

No branches or pull requests

2 participants