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

Issue warning/error if 'testpaths' does not match any files/folders #11013

Closed
nicoddemus opened this issue May 17, 2023 · 3 comments · Fixed by #11044
Closed

Issue warning/error if 'testpaths' does not match any files/folders #11013

nicoddemus opened this issue May 17, 2023 · 3 comments · Fixed by #11044
Labels
good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file

Comments

@nicoddemus
Copy link
Member

nicoddemus commented May 17, 2023

We should issue a warning (or even an error?) if testpaths does not match any files or folders.

I think an error is reasonable, even if it might break some incorrectly-configured suite out there.


Originally posted by @nicoddemus in #11006 (comment)

This is not really a bug, but an intended (albeit questionable) behavior:

The values of testpaths are actually globs, so globbing for tests in the root yields nothing. Given it finds nothing, pytest will behave as if called from the command-line without any parameters, which makes it search recursively from the current directory looking for python_files to collect.

args = []
for path in testpaths:
args.extend(sorted(glob.iglob(path, recursive=True)))

If you create the tests directory, then pytest will correctly search in that directory only.

I agree those 2 facts are surprising:

  1. The fact that testpaths is a glob. This is documented but easy to overlook, probably we should add a glob to the example there.
  2. pytest silently not finding anything, and then proceeding as usual.

I don't think we can do anything more for 1, but for 2 seems like we should at least emit a warning if testpaths is defined but does not match anything.

@nicoddemus nicoddemus added good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file labels May 17, 2023
@nicoddemus nicoddemus changed the title Issue warning if 'testpaths' does not match any files/folders Issue warning/error if 'testpaths' does not match any files/folders May 17, 2023
@RonnyPfannschmidt
Copy link
Member

i propose start with warning, elevate to error in 8.x

@nicoddemus
Copy link
Member Author

Agree, sounds good. 👍

@kenny-y-dev
Copy link
Contributor

Hello!

Adding a warning for this, will submit a PR shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor topic: config related to config handling, argument parsing and config file
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants