Test that the pythonpath plugin cleans up after itself.
(pytester: Pytester)
| 81 | |
| 82 | |
| 83 | def test_clean_up(pytester: Pytester) -> None: |
| 84 | """Test that the pythonpath plugin cleans up after itself.""" |
| 85 | # This is tough to test behaviorly because the cleanup really runs last. |
| 86 | # So the test make several implementation assumptions: |
| 87 | # - Cleanup is done in pytest_unconfigure(). |
| 88 | # - Not a hookwrapper. |
| 89 | # So we can add a hookwrapper ourselves to test what it does. |
| 90 | pytester.makefile(".ini", pytest="[pytest]\npythonpath=I_SHALL_BE_REMOVED\n") |
| 91 | pytester.makepyfile(test_foo="""def test_foo(): pass""") |
| 92 | |
| 93 | before: Optional[List[str]] = None |
| 94 | after: Optional[List[str]] = None |
| 95 | |
| 96 | class Plugin: |
| 97 | @pytest.hookimpl(hookwrapper=True, tryfirst=True) |
| 98 | def pytest_unconfigure(self) -> Generator[None, None, None]: |
| 99 | nonlocal before, after |
| 100 | before = sys.path.copy() |
| 101 | yield |
| 102 | after = sys.path.copy() |
| 103 | |
| 104 | result = pytester.runpytest_inprocess(plugins=[Plugin()]) |
| 105 | assert result.ret == 0 |
| 106 | |
| 107 | assert before is not None |
| 108 | assert after is not None |
| 109 | assert any("I_SHALL_BE_REMOVED" in entry for entry in before) |
| 110 | assert not any("I_SHALL_BE_REMOVED" in entry for entry in after) |
nothing calls this directly
no test coverage detected