MCPcopy
hub / github.com/pytest-dev/pytest / test_conftest_symlink

Function test_conftest_symlink

testing/test_conftest.py:315–357  ·  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

313
314
315def test_conftest_symlink(pytester: Pytester) -> None:
316 """`conftest.py` discovery follows normal path resolution and does not resolve symlinks."""
317 # Structure:
318 # /real
319 # /real/conftest.py
320 # /real/app
321 # /real/app/tests
322 # /real/app/tests/test_foo.py
323
324 # Links:
325 # /symlinktests -> /real/app/tests (running at symlinktests should fail)
326 # /symlink -> /real (running at /symlink should work)
327
328 real = pytester.mkdir("real")
329 realtests = real.joinpath("app/tests")
330 realtests.mkdir(parents=True)
331 symlink_or_skip(realtests, pytester.path.joinpath("symlinktests"))
332 symlink_or_skip(real, pytester.path.joinpath("symlink"))
333 pytester.makepyfile(
334 **{
335 "real/app/tests/test_foo.py": "def test1(fixture): pass",
336 "real/conftest.py": textwrap.dedent(
337 """
338 import pytest
339
340 print("conftest_loaded")
341
342 @pytest.fixture
343 def fixture():
344 print("fixture_used")
345 """
346 ),
347 }
348 )
349
350 # Should fail because conftest cannot be found from the link structure.
351 result = pytester.runpytest("-vs", "symlinktests")
352 result.stdout.fnmatch_lines(["*fixture 'fixture' not found*"])
353 assert result.ret == ExitCode.TESTS_FAILED
354
355 # Should not cause "ValueError: Plugin already registered" (#4174).
356 result = pytester.runpytest("-vs", "symlink")
357 assert result.ret == ExitCode.OK
358
359
360def 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