A monkeypatch fixture that resets context after each test.
(monkeypatch: MonkeyPatch)
| 654 | |
| 655 | @pytest.fixture(name="monkeypatch") |
| 656 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…