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