MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_conftest_symlink

Function test_conftest_symlink

testing/test_conftest.py:252–294  ·  view source on GitHub ↗

`conftest.py` discovery follows normal path resolution and does not resolve symlinks.

(pytester: Pytester)

Source from the content-addressed store, hash-verified

250
251
252def test_conftest_symlink(pytester: Pytester) -> None:
253 """`conftest.py` discovery follows normal path resolution and does not resolve symlinks."""
254 # Structure:
255 # /real
256 # /real/conftest.py
257 # /real/app
258 # /real/app/tests
259 # /real/app/tests/test_foo.py
260
261 # Links:
262 # /symlinktests -> /real/app/tests (running at symlinktests should fail)
263 # /symlink -> /real (running at /symlink should work)
264
265 real = pytester.mkdir("real")
266 realtests = real.joinpath("app/tests")
267 realtests.mkdir(parents=True)
268 symlink_or_skip(realtests, pytester.path.joinpath("symlinktests"))
269 symlink_or_skip(real, pytester.path.joinpath("symlink"))
270 pytester.makepyfile(
271 **{
272 "real/app/tests/test_foo.py": "def test1(fixture): pass",
273 "real/conftest.py": textwrap.dedent(
274 """
275 import pytest
276
277 print("conftest_loaded")
278
279 @pytest.fixture
280 def fixture():
281 print("fixture_used")
282 """
283 ),
284 }
285 )
286
287 # Should fail because conftest cannot be found from the link structure.
288 result = pytester.runpytest("-vs", "symlinktests")
289 result.stdout.fnmatch_lines(["*fixture 'fixture' not found*"])
290 assert result.ret == ExitCode.TESTS_FAILED
291
292 # Should not cause "ValueError: Plugin already registered" (#4174).
293 result = pytester.runpytest("-vs", "symlink")
294 assert result.ret == ExitCode.OK
295
296
297def test_conftest_symlink_files(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

symlink_or_skipFunction · 0.90
fnmatch_linesMethod · 0.80
mkdirMethod · 0.45
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected