Fix/improve handling of pkg init and test file via args
Ref: https://github.com/pytest-dev/pytest/issues/4344#issuecomment-441095934
This commit is contained in:
parent
386e801a5a
commit
61b9246afe
|
@ -0,0 +1 @@
|
||||||
|
Fix/improve collection of args when passing in ``__init__.py`` and a test file.
|
|
@ -582,7 +582,7 @@ class Session(nodes.FSCollector):
|
||||||
col = self._node_cache[argpath]
|
col = self._node_cache[argpath]
|
||||||
else:
|
else:
|
||||||
collect_root = self._pkg_roots.get(argpath.dirname, self)
|
collect_root = self._pkg_roots.get(argpath.dirname, self)
|
||||||
col = collect_root._collectfile(argpath)
|
col = collect_root._collectfile(argpath, handle_dupes=False)
|
||||||
if col:
|
if col:
|
||||||
self._node_cache[argpath] = col
|
self._node_cache[argpath] = col
|
||||||
m = self.matchnodes(col, names)
|
m = self.matchnodes(col, names)
|
||||||
|
|
|
@ -1157,3 +1157,32 @@ def test_collectignore_via_conftest(testdir, monkeypatch):
|
||||||
|
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
assert result.ret == EXIT_NOTESTSCOLLECTED
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
||||||
|
|
||||||
|
|
||||||
|
def test_collect_pkg_init_and_file_in_args(testdir):
|
||||||
|
subdir = testdir.mkdir("sub")
|
||||||
|
init = subdir.ensure("__init__.py")
|
||||||
|
init.write("def test_init(): pass")
|
||||||
|
p = subdir.ensure("test_file.py")
|
||||||
|
p.write("def test_file(): pass")
|
||||||
|
|
||||||
|
# NOTE: without "-o python_files=*.py" this collects test_file.py twice.
|
||||||
|
# This changed/broke with "Add package scoped fixtures #2283" (2b1410895)
|
||||||
|
# initially (causing a RecursionError).
|
||||||
|
result = testdir.runpytest("-v", str(init), str(p))
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"sub/test_file.py::test_file PASSED*",
|
||||||
|
"sub/test_file.py::test_file PASSED*",
|
||||||
|
"*2 passed in*",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
result = testdir.runpytest("-v", "-o", "python_files=*.py", str(init), str(p))
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"sub/__init__.py::test_init PASSED*",
|
||||||
|
"sub/test_file.py::test_file PASSED*",
|
||||||
|
"*2 passed in*",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue