Add warning when testpaths is set but paths are not found by glob (#11044)
Closes #11013 --------- Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
parent
fbfd4b5005
commit
7c231baa64
1
AUTHORS
1
AUTHORS
|
@ -197,6 +197,7 @@ Justice Ndou
|
||||||
Justyna Janczyszyn
|
Justyna Janczyszyn
|
||||||
Kale Kundert
|
Kale Kundert
|
||||||
Kamran Ahmad
|
Kamran Ahmad
|
||||||
|
Kenny Y
|
||||||
Karl O. Pinc
|
Karl O. Pinc
|
||||||
Karthikeyan Singaravelan
|
Karthikeyan Singaravelan
|
||||||
Katarzyna Jachim
|
Katarzyna Jachim
|
||||||
|
|
|
@ -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.
|
|
@ -1382,6 +1382,15 @@ class Config:
|
||||||
args = []
|
args = []
|
||||||
for path in testpaths:
|
for path in testpaths:
|
||||||
args.extend(sorted(glob.iglob(path, recursive=True)))
|
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:
|
if not args:
|
||||||
source = Config.ArgsSource.INCOVATION_DIR
|
source = Config.ArgsSource.INCOVATION_DIR
|
||||||
args = [str(self.invocation_params.dir)]
|
args = [str(self.invocation_params.dir)]
|
||||||
|
|
|
@ -777,6 +777,20 @@ class TestStackLevel:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
def test_resource_warning(pytester: Pytester, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
# Some platforms (notably PyPy) don't have tracemalloc.
|
# Some platforms (notably PyPy) don't have tracemalloc.
|
||||||
# We choose to explicitly not skip this in case tracemalloc is not
|
# We choose to explicitly not skip this in case tracemalloc is not
|
||||||
|
|
Loading…
Reference in New Issue