Skip to content

Commit 5d9f74b

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

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

testing/_py/test_local.py

Lines changed: 6 additions & 0 deletions
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,11 @@ def test_error_preservation(self, path1):
978979

979980

980981
class TestImport:
982+
@pytest.fixture(autouse=True)
983+
def preserve_sys_modules(self):
984+
with mock.patch.dict(sys.modules):
985+
pass
986+
981987
def test_pyimport(self, path1):
982988
obj = path1.join("execfile.py").pyimport()
983989
assert obj.x == 42

testing/test_pathlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ 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_modules(self):
96+
with unittest.mock.patch.dict(sys.modules):
97+
yield
98+
9499
def setuptestfs(self, path: Path) -> None:
95100
# print "setting up test fs for", repr(path)
96101
samplefile = path / "samplefile"

0 commit comments

Comments
 (0)