Tests: Add monkeypatch_session fixture

This commit is contained in:
Mike Salvatore 2021-07-19 08:11:58 -04:00
parent 2897755cae
commit 5222230487
1 changed files with 11 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import sys
from pathlib import Path from pathlib import Path
import pytest import pytest
from _pytest.monkeypatch import MonkeyPatch
MONKEY_BASE_PATH = str(Path(__file__).parent.parent.parent) MONKEY_BASE_PATH = str(Path(__file__).parent.parent.parent)
sys.path.insert(0, MONKEY_BASE_PATH) sys.path.insert(0, MONKEY_BASE_PATH)
@ -28,3 +29,13 @@ def patched_home_env(monkeypatch, tmp_path):
monkeypatch.setenv("HOME", str(tmp_path)) monkeypatch.setenv("HOME", str(tmp_path))
return 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()