Fix "Plugin already registered" error with symlinks
Fixes https://github.com/pytest-dev/pytest/issues/4174.
This commit is contained in:
		
							parent
							
								
									799b72cf6f
								
							
						
					
					
						commit
						fadac0ffc0
					
				|  | @ -0,0 +1 @@ | ||||||
|  | Fix "ValueError: Plugin already registered" with conftest plugins via symlink. | ||||||
|  | @ -391,7 +391,7 @@ class PytestPluginManager(PluginManager): | ||||||
|             # and allow users to opt into looking into the rootdir parent |             # and allow users to opt into looking into the rootdir parent | ||||||
|             # directories instead of requiring to specify confcutdir |             # directories instead of requiring to specify confcutdir | ||||||
|             clist = [] |             clist = [] | ||||||
|             for parent in directory.parts(): |             for parent in directory.realpath().parts(): | ||||||
|                 if self._confcutdir and self._confcutdir.relto(parent): |                 if self._confcutdir and self._confcutdir.relto(parent): | ||||||
|                     continue |                     continue | ||||||
|                 conftestpath = parent.join("conftest.py") |                 conftestpath = parent.join("conftest.py") | ||||||
|  |  | ||||||
|  | @ -192,8 +192,10 @@ def test_conftest_confcutdir(testdir): | ||||||
| ) | ) | ||||||
| def test_conftest_symlink(testdir): | def test_conftest_symlink(testdir): | ||||||
|     """Ensure that conftest.py is used for resolved symlinks.""" |     """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("symlinktests").mksymlinkto(realtests) | ||||||
|  |     testdir.tmpdir.join("symlink").mksymlinkto(real) | ||||||
|     testdir.makepyfile( |     testdir.makepyfile( | ||||||
|         **{ |         **{ | ||||||
|             "real/app/tests/test_foo.py": "def test1(fixture): pass", |             "real/app/tests/test_foo.py": "def test1(fixture): pass", | ||||||
|  | @ -220,6 +222,10 @@ def test_conftest_symlink(testdir): | ||||||
|     ) |     ) | ||||||
|     assert result.ret == EXIT_OK |     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") |     realtests.ensure("__init__.py") | ||||||
|     result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1") |     result = testdir.runpytest("-vs", "symlinktests/test_foo.py::test1") | ||||||
|     result.stdout.fnmatch_lines( |     result.stdout.fnmatch_lines( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue