Fix "Plugin already registered" error with symlinks

Fixes https://github.com/pytest-dev/pytest/issues/4174.
This commit is contained in:
Daniel Hahler 2018-10-22 13:57:01 +02:00
parent 799b72cf6f
commit fadac0ffc0
3 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix "ValueError: Plugin already registered" with conftest plugins via symlink.

View File

@ -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")

View File

@ -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(