Skip to content

Commit

Permalink
fix test pollution of sys.modules
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 20, 2022
1 parent 82344ba commit 5d9f74b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions testing/_py/test_local.py
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import time
from unittest import mock

import pytest
from py import error
Expand Down Expand Up @@ -978,6 +979,11 @@ def test_error_preservation(self, path1):


class TestImport:
@pytest.fixture(autouse=True)
def preserve_sys_modules(self):
with mock.patch.dict(sys.modules):
pass

def test_pyimport(self, path1):
obj = path1.join("execfile.py").pyimport()
assert obj.x == 42
Expand Down
5 changes: 5 additions & 0 deletions testing/test_pathlib.py
Expand Up @@ -91,6 +91,11 @@ def path1(self, tmp_path_factory: TempPathFactory) -> Generator[Path, None, None
yield path
assert path.joinpath("samplefile").exists()

@pytest.fixture(autouse=True)
def preserve_sys_modules(self):
with unittest.mock.patch.dict(sys.modules):
yield

def setuptestfs(self, path: Path) -> None:
# print "setting up test fs for", repr(path)
samplefile = path / "samplefile"
Expand Down

0 comments on commit 5d9f74b

Please sign in to comment.