From 5222230487006abcbf14b729c655caeadf24f834 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 19 Jul 2021 08:11:58 -0400 Subject: [PATCH] Tests: Add monkeypatch_session fixture --- monkey/tests/unit_tests/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/monkey/tests/unit_tests/conftest.py b/monkey/tests/unit_tests/conftest.py index 64b2737c4..3099263b0 100644 --- a/monkey/tests/unit_tests/conftest.py +++ b/monkey/tests/unit_tests/conftest.py @@ -3,6 +3,7 @@ import sys from pathlib import Path import pytest +from _pytest.monkeypatch import MonkeyPatch MONKEY_BASE_PATH = str(Path(__file__).parent.parent.parent) sys.path.insert(0, MONKEY_BASE_PATH) @@ -28,3 +29,13 @@ def patched_home_env(monkeypatch, tmp_path): monkeypatch.setenv("HOME", str(tmp_path)) return tmp_path + + +# The monkeypatch fixture is function scoped, so it cannot be used by session-scoped fixtures. This +# monkeypatch_session fixture can be session-scoped. For more information, see +# https://github.com/pytest-dev/pytest/issues/363#issuecomment-406536200 +@pytest.fixture(scope="session") +def monkeypatch_session(): + monkeypatch_ = MonkeyPatch() + yield monkeypatch_ + monkeypatch_.undo()