MCPcopy
hub / github.com/pytest-dev/pytest / test_clean_up

Function test_clean_up

testing/test_python_path.py:104–130  ·  testing/test_python_path.py::test_clean_up

Test that the plugin cleans up after itself.

(pytester: Pytester)

Source from the content-addressed store, hash-verified

102
103
104def 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)

Callers

nothing calls this directly

Calls 5

copyMethod · 0.80
PluginClass · 0.70
makefileMethod · 0.45
makepyfileMethod · 0.45
runpytest_inprocessMethod · 0.45

Tested by

no test coverage detected