diff --git a/AUTHORS b/AUTHORS index 30908870783..77d64712683 100644 --- a/AUTHORS +++ b/AUTHORS @@ -197,6 +197,7 @@ Justice Ndou Justyna Janczyszyn Kale Kundert Kamran Ahmad +Kenny Y Karl O. Pinc Karthikeyan Singaravelan Katarzyna Jachim diff --git a/changelog/11013.improvement.rst b/changelog/11013.improvement.rst new file mode 100644 index 00000000000..fe3ece93c23 --- /dev/null +++ b/changelog/11013.improvement.rst @@ -0,0 +1 @@ +Added warning when :confval:`testpaths` is set, but paths are not found by glob. In this case, pytest will fall back to searching from the current directory. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 6df06f7b281..23b17b9a697 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1382,6 +1382,15 @@ def parse(self, args: List[str], addopts: bool = True) -> None: args = [] for path in testpaths: args.extend(sorted(glob.iglob(path, recursive=True))) + if testpaths and not args: + warning_text = ( + "No files were found in testpaths; " + "consider removing or adjusting your testpaths configuration. " + "Searching recursively from the 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)] diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 7b716bb4546..a1ecba2476e 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -777,6 +777,20 @@ def test_it(): ) +def test_warning_on_testpaths_not_found(pytester: Pytester) -> None: + # Check for warning when testpaths set, but not found by glob + pytester.makeini( + """ + [pytest] + testpaths = absent + """ + ) + result = pytester.runpytest() + result.stdout.fnmatch_lines( + ["*ConfigWarning: No files were found in testpaths*", "*1 warning*"] + ) + + def test_resource_warning(pytester: Pytester, monkeypatch: pytest.MonkeyPatch) -> None: # Some platforms (notably PyPy) don't have tracemalloc. # We choose to explicitly not skip this in case tracemalloc is not