Skip to content

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

@nicoddemus

Description

@nicoddemus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortopic: configrelated to config handling, argument parsing and config file

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions