diff --git a/changelog/4405.bugfix.rst b/changelog/4405.bugfix.rst new file mode 100644 index 000000000..ac05091c1 --- /dev/null +++ b/changelog/4405.bugfix.rst @@ -0,0 +1 @@ +Fix collection of testpaths with ``--pyargs``. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 60b455bb3..0c3ecdcce 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -852,10 +852,7 @@ class Config(object): ) if not args: if self.invocation_dir == self.rootdir: - args = [ - str(self.invocation_dir.join(x, abs=True)) - for x in self.getini("testpaths") - ] + args = self.getini("testpaths") if not args: args = [str(self.invocation_dir)] self.args = args diff --git a/testing/test_collection.py b/testing/test_collection.py index 9385f5461..fae23025e 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -1086,6 +1086,28 @@ def test_collect_with_chdir_during_import(testdir): result.stdout.fnmatch_lines(["collected 1 item"]) +def test_collect_pyargs_with_testpaths(testdir, monkeypatch): + testmod = testdir.mkdir("testmod") + # NOTE: __init__.py is not collected since it does not match python_files. + testmod.ensure("__init__.py").write("def test_func(): pass") + testmod.ensure("test_file.py").write("def test_func(): pass") + + root = testdir.mkdir("root") + root.ensure("pytest.ini").write( + textwrap.dedent( + """ + [pytest] + addopts = --pyargs + testpaths = testmod + """ + ) + ) + monkeypatch.setenv("PYTHONPATH", str(testdir.tmpdir)) + with root.as_cwd(): + result = testdir.runpytest_subprocess() + result.stdout.fnmatch_lines(["*1 passed in*"]) + + @pytest.mark.skipif( not hasattr(py.path.local, "mksymlinkto"), reason="symlink not available on this platform",