MCPcopy
hub / github.com/conda/conda / context_aware_monkeypatch

Function context_aware_monkeypatch

conda/testing/fixtures.py:656–671  ·  view source on GitHub ↗

A monkeypatch fixture that resets context after each test.

(monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

654
655@pytest.fixture(name="monkeypatch")
656def context_aware_monkeypatch(monkeypatch: MonkeyPatch) -> MonkeyPatch:
657 """A monkeypatch fixture that resets context after each test."""
658 yield monkeypatch
659
660 # reset context if any CONDA_ variables were set/unset
661 if conda_vars := [
662 name
663 for obj, name, _ in monkeypatch._setitem
664 if obj is os.environ and name.startswith("CONDA_")
665 ]:
666 log.debug(
667 "monkeypatch cleanup: undo & reset context: %s", ", ".join(conda_vars)
668 )
669 monkeypatch.undo()
670 # reload context without search paths
671 reset_context([])
672
673
674@pytest.fixture

Callers

nothing calls this directly

Calls 3

reset_contextFunction · 0.90
debugMethod · 0.80
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…