Skip to content

Commit

Permalink
Add warning when testpaths is set but paths are not found by glob (#1…
Browse files Browse the repository at this point in the history
…1044)

Closes #11013

---------

Co-authored-by: Ran Benita <ran@unusedvar.com>
  • Loading branch information
kenny-y-dev and bluetech committed May 30, 2023
1 parent fbfd4b5 commit 7c231ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -197,6 +197,7 @@ Justice Ndou
Justyna Janczyszyn
Kale Kundert
Kamran Ahmad
Kenny Y
Karl O. Pinc
Karthikeyan Singaravelan
Katarzyna Jachim
Expand Down
1 change: 1 addition & 0 deletions 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.
9 changes: 9 additions & 0 deletions src/_pytest/config/__init__.py
Expand Up @@ -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)]
Expand Down
14 changes: 14 additions & 0 deletions testing/test_warnings.py
Expand Up @@ -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
Expand Down

0 comments on commit 7c231ba

Please sign in to comment.