Skip to content

Commit 2137e2b

Browse files
authored
Merge pull request #3846 from nicoddemus/issue-3843
Fix collection error when tests is specified with --doctest-modules
2 parents 3b521be + 07a560f commit 2137e2b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

changelog/3843.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix collection error when specifying test functions directly in the command line using ``test.py::test`` syntax together with ``--doctest-module``.

src/_pytest/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,12 @@ def _matchnodes(self, matching, names):
625625
resultnodes.append(node)
626626
continue
627627
assert isinstance(node, nodes.Collector)
628-
if node.nodeid in self._node_cache:
629-
rep = self._node_cache[node.nodeid]
628+
key = (type(node), node.nodeid)
629+
if key in self._node_cache:
630+
rep = self._node_cache[key]
630631
else:
631632
rep = collect_one_node(node)
632-
self._node_cache[node.nodeid] = rep
633+
self._node_cache[key] = rep
633634
if rep.passed:
634635
has_matched = False
635636
for x in rep.result:

testing/acceptance_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ def join_pythonpath(*dirs):
660660
["*test_world.py::test_other*PASSED*", "*1 passed*"]
661661
)
662662

663+
def test_invoke_test_and_doctestmodules(self, testdir):
664+
p = testdir.makepyfile(
665+
"""
666+
def test():
667+
pass
668+
"""
669+
)
670+
result = testdir.runpytest(str(p) + "::test", "--doctest-modules")
671+
result.stdout.fnmatch_lines(["*1 passed*"])
672+
663673
@pytest.mark.skipif(not hasattr(os, "symlink"), reason="requires symlinks")
664674
def test_cmdline_python_package_symlink(self, testdir, monkeypatch):
665675
"""

0 commit comments

Comments
 (0)