Test that the plugin cleans up after itself.
(pytester: Pytester)
| 102 | |
| 103 | |
| 104 | def test_clean_up(pytester: Pytester) -> None: |
| 105 | class="st">""class="st">"Test that the plugin cleans up after itself."class="st">"" |
| 106 | class="cm"># This is tough to test behaviorally because the cleanup really runs last. |
| 107 | class="cm"># So the test make several implementation assumptions: |
| 108 | class="cm"># - Cleanup is done in pytest_unconfigure(). |
| 109 | class="cm"># - Not a hook wrapper. |
| 110 | class="cm"># So we can add a hook wrapper ourselves to test what it does. |
| 111 | pytester.makefile(class="st">".ini", pytest=class="st">"[pytest]\npythonpath=I_SHALL_BE_REMOVED\n") |
| 112 | pytester.makepyfile(test_foo=class="st">""class="st">"def test_foo(): pass"class="st">"") |
| 113 | |
| 114 | before: list[str] | None = None |
| 115 | after: list[str] | None = None |
| 116 | |
| 117 | class Plugin: |
| 118 | @pytest.hookimpl(tryfirst=True) |
| 119 | def pytest_unconfigure(self) -> None: |
| 120 | nonlocal before |
| 121 | before = sys.path.copy() |
| 122 | |
| 123 | result = pytester.runpytest_inprocess(plugins=[Plugin()]) |
| 124 | after = sys.path.copy() |
| 125 | assert result.ret == 0 |
| 126 | |
| 127 | assert before is not None |
| 128 | assert after is not None |
| 129 | assert any(class="st">"I_SHALL_BE_REMOVED" in entry for entry in before) |
| 130 | assert not any(class="st">"I_SHALL_BE_REMOVED" in entry for entry in after) |
nothing calls this directly
no test coverage detected