Skip to content

Commit 72d98a7

Browse files
authored
Merge pull request #4214 from blueyed/fix-4174
Fix "Plugin already registered" error with symlinks
2 parents 799b72c + fadac0f commit 72d98a7

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

changelog/4174.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix "ValueError: Plugin already registered" with conftest plugins via symlink.

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _getconftestmodules(self, path):
391391
# and allow users to opt into looking into the rootdir parent
392392
# directories instead of requiring to specify confcutdir
393393
clist = []
394-
for parent in directory.parts():
394+
for parent in directory.realpath().parts():
395395
if self._confcutdir and self._confcutdir.relto(parent):
396396
continue
397397
conftestpath = parent.join("conftest.py")

testing/test_conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,10 @@ def pytest_addoption(parser):
192192
)
193193
def test_conftest_symlink(testdir):
194194
"""Ensure that conftest.py is used for resolved symlinks."""
195-
realtests = testdir.tmpdir.mkdir("real").mkdir("app").mkdir("tests")
195+
real = testdir.tmpdir.mkdir("real")
196+
realtests = real.mkdir("app").mkdir("tests")
196197
testdir.tmpdir.join("symlinktests").mksymlinkto(realtests)
198+
testdir.tmpdir.join("symlink").mksymlinkto(real)
197199
testdir.makepyfile(
198200
**{
199201
"real/app/tests/test_foo.py": "def test1(fixture): pass",
@@ -220,6 +222,10 @@ def fixture():
220222
)
221223
assert result.ret == EXIT_OK
222224

225+
# Should not cause "ValueError: Plugin already registered" (#4174).
226+
result = testdir.runpytest("-vs", "symlink")
227+
assert result.ret == EXIT_OK
228+
223229
realtests.ensure("__init__.py")
224230
result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1")
225231
result.stdout.fnmatch_lines(

0 commit comments

Comments
 (0)