From fadac0ffc0102f8ba536f3848623f67c81bb11a2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 22 Oct 2018 13:57:01 +0200 Subject: [PATCH] Fix "Plugin already registered" error with symlinks Fixes https://github.com/pytest-dev/pytest/issues/4174. --- changelog/4174.bugfix.rst | 1 + src/_pytest/config/__init__.py | 2 +- testing/test_conftest.py | 8 +++++++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelog/4174.bugfix.rst diff --git a/changelog/4174.bugfix.rst b/changelog/4174.bugfix.rst new file mode 100644 index 000000000..5e263c23a --- /dev/null +++ b/changelog/4174.bugfix.rst @@ -0,0 +1 @@ +Fix "ValueError: Plugin already registered" with conftest plugins via symlink. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 88cbf14ba..47e5c2945 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -391,7 +391,7 @@ class PytestPluginManager(PluginManager): # and allow users to opt into looking into the rootdir parent # directories instead of requiring to specify confcutdir clist = [] - for parent in directory.parts(): + for parent in directory.realpath().parts(): if self._confcutdir and self._confcutdir.relto(parent): continue conftestpath = parent.join("conftest.py") diff --git a/testing/test_conftest.py b/testing/test_conftest.py index a2df0ae37..44126613e 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -192,8 +192,10 @@ def test_conftest_confcutdir(testdir): ) def test_conftest_symlink(testdir): """Ensure that conftest.py is used for resolved symlinks.""" - realtests = testdir.tmpdir.mkdir("real").mkdir("app").mkdir("tests") + real = testdir.tmpdir.mkdir("real") + realtests = real.mkdir("app").mkdir("tests") testdir.tmpdir.join("symlinktests").mksymlinkto(realtests) + testdir.tmpdir.join("symlink").mksymlinkto(real) testdir.makepyfile( **{ "real/app/tests/test_foo.py": "def test1(fixture): pass", @@ -220,6 +222,10 @@ def test_conftest_symlink(testdir): ) assert result.ret == EXIT_OK + # Should not cause "ValueError: Plugin already registered" (#4174). + result = testdir.runpytest("-vs", "symlink") + assert result.ret == EXIT_OK + realtests.ensure("__init__.py") result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1") result.stdout.fnmatch_lines(