From 14d1d950cd6a2158d9908889d8189c579775a8e8 Mon Sep 17 00:00:00 2001 From: Kenny Y <24802984+kenny-y-dev@users.noreply.github.com> Date: Sat, 27 May 2023 19:14:53 -0400 Subject: [PATCH] Add warning when testpaths is set but paths are not found by glob --- changelog/11013.improvement.rst | 1 + src/_pytest/config/__init__.py | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 changelog/11013.improvement.rst diff --git a/changelog/11013.improvement.rst b/changelog/11013.improvement.rst new file mode 100644 index 000000000..3fa062243 --- /dev/null +++ b/changelog/11013.improvement.rst @@ -0,0 +1 @@ +Added warning when testpaths is set, but paths are not found by glob. In this case, pytest will search fall back to searching from current directory. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 6df06f7b2..b5e691094 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1382,6 +1382,14 @@ class Config: args = [] for path in testpaths: args.extend(sorted(glob.iglob(path, recursive=True))) + if testpaths and not args: + warning_text = ( + "testpaths defined but path not found, " + "will search recursively from current directory instead" + ) + self.issue_config_time_warning( + PytestConfigWarning(warning_text), stacklevel=3 + ) if not args: source = Config.ArgsSource.INCOVATION_DIR args = [str(self.invocation_params.dir)]