`conftest.py` discovery follows normal path resolution and does not resolve symlinks.
(pytester: Pytester)
| 313 | |
| 314 | |
| 315 | def 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 | |
| 360 | def test_conftest_symlink_files(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected