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

Function test_clean_up

testing/test_python_path.py:104–130  ·  view source on GitHub ↗

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 """Test that the plugin cleans up after itself."""
106 # This is tough to test behaviorally because the cleanup really runs last.
107 # So the test make several implementation assumptions:
108 # - Cleanup is done in pytest_unconfigure().
109 # - Not a hook wrapper.
110 # So we can add a hook wrapper ourselves to test what it does.
111 pytester.makefile(".ini", pytest="[pytest]\npythonpath=I_SHALL_BE_REMOVED\n")
112 pytester.makepyfile(test_foo="""def test_foo(): pass""")
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("I_SHALL_BE_REMOVED" in entry for entry in before)
130 assert not any("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

Used in the wild real call sites across dependent graphs

searching dependent graphs…