From 7a291b7cf64adcc46c90b29fed045baa570a541a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2019 18:43:51 +0100 Subject: [PATCH] WIP: Fix handling of pkg init and test file via args [ci skip] Ref: https://github.com/pytest-dev/pytest/issues/4344#issuecomment-441095934 --- src/_pytest/main.py | 2 +- testing/test_collection.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 68d5bac40d1..8c67cf08465 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -592,7 +592,7 @@ def filter_(f): col = self._node_cache[argpath] else: collect_root = self._pkg_roots.get(argpath.dirname, self) - col = collect_root._collectfile(argpath) + col = collect_root._collectfile(argpath, handle_dupes=False) if col: self._node_cache[argpath] = col m = self.matchnodes(col, names) diff --git a/testing/test_collection.py b/testing/test_collection.py index 329182b0f1e..735c6512851 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1157,3 +1157,18 @@ def test_collectignore_via_conftest(testdir, monkeypatch): result = testdir.runpytest() 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") + + result = testdir.runpytest("-v", str(init), str(p), str(p)) + result.stdout.fnmatch_lines([ + "sub/__init__.py PASSED*", + "sub/test_file.py PASSED*", + "*2 passed in*", + ])