Skip to content

Commit dc0cb0d

Browse files
committed
fix test pollution of sys.modules
1 parent 82344ba commit dc0cb0d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

testing/_py/test_local.py

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from unittest import mock
56

67
import pytest
78
from py import error
@@ -978,6 +979,12 @@ def test_error_preservation(self, path1):
978979

979980

980981
class TestImport:
982+
@pytest.fixture(autouse=True)
983+
def preserve_sys(self):
984+
with mock.patch.dict(sys.modules):
985+
with mock.patch.object(sys, "path", list(sys.path)):
986+
yield
987+
981988
def test_pyimport(self, path1):
982989
obj = path1.join("execfile.py").pyimport()
983990
assert obj.x == 42

testing/test_pathlib.py

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ def path1(self, tmp_path_factory: TempPathFactory) -> Generator[Path, None, None
9191
yield path
9292
assert path.joinpath("samplefile").exists()
9393

94+
@pytest.fixture(autouse=True)
95+
def preserve_sys(self):
96+
with unittest.mock.patch.dict(sys.modules):
97+
with unittest.mock.patch.object(sys, "path", list(sys.path)):
98+
yield
99+
94100
def setuptestfs(self, path: Path) -> None:
95101
# print "setting up test fs for", repr(path)
96102
samplefile = path / "samplefile"

0 commit comments

Comments
 (0)