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