fix test pollution of sys.modules
This commit is contained in:
parent
82344ba4f8
commit
dc0cb0d149
|
@ -2,6 +2,7 @@ import multiprocessing
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from py import error
|
||||
|
@ -978,6 +979,12 @@ class TestExecution:
|
|||
|
||||
|
||||
class TestImport:
|
||||
@pytest.fixture(autouse=True)
|
||||
def preserve_sys(self):
|
||||
with mock.patch.dict(sys.modules):
|
||||
with mock.patch.object(sys, "path", list(sys.path)):
|
||||
yield
|
||||
|
||||
def test_pyimport(self, path1):
|
||||
obj = path1.join("execfile.py").pyimport()
|
||||
assert obj.x == 42
|
||||
|
|
|
@ -91,6 +91,12 @@ class TestImportPath:
|
|||
yield path
|
||||
assert path.joinpath("samplefile").exists()
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def preserve_sys(self):
|
||||
with unittest.mock.patch.dict(sys.modules):
|
||||
with unittest.mock.patch.object(sys, "path", list(sys.path)):
|
||||
yield
|
||||
|
||||
def setuptestfs(self, path: Path) -> None:
|
||||
# print "setting up test fs for", repr(path)
|
||||
samplefile = path / "samplefile"
|
||||
|
|
Loading…
Reference in New Issue