(self, pytester: Pytester)
| 463 | |
| 464 | class TestConftestVisibility: |
| 465 | def _setup_tree(self, pytester: Pytester) -> Dict[str, Path]: # for issue616 |
| 466 | # example mostly taken from: |
| 467 | # https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html |
| 468 | runner = pytester.mkdir("empty") |
| 469 | package = pytester.mkdir("package") |
| 470 | |
| 471 | package.joinpath("conftest.py").write_text( |
| 472 | textwrap.dedent( |
| 473 | """\ |
| 474 | import pytest |
| 475 | @pytest.fixture |
| 476 | def fxtr(): |
| 477 | return "from-package" |
| 478 | """ |
| 479 | ) |
| 480 | ) |
| 481 | package.joinpath("test_pkgroot.py").write_text( |
| 482 | textwrap.dedent( |
| 483 | """\ |
| 484 | def test_pkgroot(fxtr): |
| 485 | assert fxtr == "from-package" |
| 486 | """ |
| 487 | ) |
| 488 | ) |
| 489 | |
| 490 | swc = package.joinpath("swc") |
| 491 | swc.mkdir() |
| 492 | swc.joinpath("__init__.py").touch() |
| 493 | swc.joinpath("conftest.py").write_text( |
| 494 | textwrap.dedent( |
| 495 | """\ |
| 496 | import pytest |
| 497 | @pytest.fixture |
| 498 | def fxtr(): |
| 499 | return "from-swc" |
| 500 | """ |
| 501 | ) |
| 502 | ) |
| 503 | swc.joinpath("test_with_conftest.py").write_text( |
| 504 | textwrap.dedent( |
| 505 | """\ |
| 506 | def test_with_conftest(fxtr): |
| 507 | assert fxtr == "from-swc" |
| 508 | """ |
| 509 | ) |
| 510 | ) |
| 511 | |
| 512 | snc = package.joinpath("snc") |
| 513 | snc.mkdir() |
| 514 | snc.joinpath("__init__.py").touch() |
| 515 | snc.joinpath("test_no_conftest.py").write_text( |
| 516 | textwrap.dedent( |
| 517 | """\ |
| 518 | def test_no_conftest(fxtr): |
| 519 | assert fxtr == "from-package" # No local conftest.py, so should |
| 520 | # use value from parent dir's |
| 521 | """ |
| 522 | ) |
no test coverage detected