Skip to content

Commit 97cd5f0

Browse files
authored
Merge pull request #5094 from blueyed/merge-master
Merge master into festures
2 parents b375937 + 8b2fcf5 commit 97cd5f0

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

src/_pytest/pytester.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ def testdir(request, tmpdir_factory):
344344
return Testdir(request, tmpdir_factory)
345345

346346

347+
@pytest.fixture
348+
def _sys_snapshot():
349+
snappaths = SysPathsSnapshot()
350+
snapmods = SysModulesSnapshot()
351+
yield
352+
snapmods.restore()
353+
snappaths.restore()
354+
355+
347356
@pytest.fixture
348357
def _config_for_test():
349358
from _pytest.config import get_config

testing/acceptance_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def test_foo(invalid_fixture):
485485
["*source code not available*", "E*fixture 'invalid_fixture' not found"]
486486
)
487487

488-
def test_plugins_given_as_strings(self, tmpdir, monkeypatch):
488+
def test_plugins_given_as_strings(self, tmpdir, monkeypatch, _sys_snapshot):
489489
"""test that str values passed to main() as `plugins` arg
490490
are interpreted as module names to be imported and registered.
491491
#855.

testing/code/test_excinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def test_division_zero():
441441

442442
class TestFormattedExcinfo(object):
443443
@pytest.fixture
444-
def importasmod(self, request):
444+
def importasmod(self, request, _sys_snapshot):
445445
def importasmod(source):
446446
source = textwrap.dedent(source)
447447
tmpdir = request.getfixturevalue("tmpdir")

testing/code/test_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def g():
410410
assert lines == ["def f():", " def g():", " pass"]
411411

412412

413-
def test_source_of_class_at_eof_without_newline(tmpdir):
413+
def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot):
414414
# this test fails because the implicit inspect.getsource(A) below
415415
# does not return the "x = 1" last line.
416416
source = _pytest._code.Source(

testing/test_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_iter_rewritable_modules(self, names, expected):
436436

437437

438438
class TestConfigFromdictargs(object):
439-
def test_basic_behavior(self):
439+
def test_basic_behavior(self, _sys_snapshot):
440440
from _pytest.config import Config
441441

442442
option_dict = {"verbose": 444, "foo": "bar", "capture": "no"}
@@ -450,7 +450,7 @@ def test_basic_behavior(self):
450450
assert config.option.capture == "no"
451451
assert config.args == args
452452

453-
def test_origargs(self):
453+
def test_origargs(self, _sys_snapshot):
454454
"""Show that fromdictargs can handle args in their "orig" format"""
455455
from _pytest.config import Config
456456

@@ -1057,7 +1057,7 @@ def test_with_existing_file_in_subdir(self, tmpdir):
10571057
assert rootdir == tmpdir
10581058
assert inifile is None
10591059

1060-
def test_addopts_before_initini(self, monkeypatch, _config_for_test):
1060+
def test_addopts_before_initini(self, monkeypatch, _config_for_test, _sys_snapshot):
10611061
cache_dir = ".custom_cache"
10621062
monkeypatch.setenv("PYTEST_ADDOPTS", "-o cache_dir=%s" % cache_dir)
10631063
config = _config_for_test
@@ -1092,7 +1092,7 @@ def test_addopts_from_ini_not_concatenated(self, testdir):
10921092
)
10931093
assert result.ret == _pytest.main.EXIT_USAGEERROR
10941094

1095-
def test_override_ini_does_not_contain_paths(self, _config_for_test):
1095+
def test_override_ini_does_not_contain_paths(self, _config_for_test, _sys_snapshot):
10961096
"""Check that -o no longer swallows all options after it (#3103)"""
10971097
config = _config_for_test
10981098
config._preparse(["-o", "cache_dir=/cache", "/some/test/path"])

testing/test_conftest.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
from _pytest.main import EXIT_USAGEERROR
1414

1515

16-
@pytest.fixture(scope="module", params=["global", "inpackage"])
17-
def basedir(request, tmpdir_factory):
18-
tmpdir = tmpdir_factory.mktemp("basedir", numbered=True)
19-
tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
20-
tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
21-
if request.param == "inpackage":
22-
tmpdir.ensure("adir/__init__.py")
23-
tmpdir.ensure("adir/b/__init__.py")
24-
return tmpdir
25-
26-
2716
def ConftestWithSetinitial(path):
2817
conftest = PytestPluginManager()
2918
conftest_setinitial(conftest, [path])
@@ -41,18 +30,30 @@ def __init__(self):
4130
conftest._set_initial_conftests(Namespace())
4231

4332

33+
@pytest.mark.usefixtures("_sys_snapshot")
4434
class TestConftestValueAccessGlobal(object):
35+
@pytest.fixture(scope="module", params=["global", "inpackage"])
36+
def basedir(self, request, tmpdir_factory):
37+
tmpdir = tmpdir_factory.mktemp("basedir", numbered=True)
38+
tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3")
39+
tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5")
40+
if request.param == "inpackage":
41+
tmpdir.ensure("adir/__init__.py")
42+
tmpdir.ensure("adir/b/__init__.py")
43+
44+
yield tmpdir
45+
4546
def test_basic_init(self, basedir):
4647
conftest = PytestPluginManager()
4748
p = basedir.join("adir")
4849
assert conftest._rget_with_confmod("a", p)[1] == 1
4950

5051
def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
5152
conftest = PytestPluginManager()
52-
len(conftest._dirpath2confmods)
53+
assert not len(conftest._dirpath2confmods)
5354
conftest._getconftestmodules(basedir)
5455
snap1 = len(conftest._dirpath2confmods)
55-
# assert len(conftest._dirpath2confmods) == snap1 + 1
56+
assert snap1 == 1
5657
conftest._getconftestmodules(basedir.join("adir"))
5758
assert len(conftest._dirpath2confmods) == snap1 + 1
5859
conftest._getconftestmodules(basedir.join("b"))
@@ -80,7 +81,7 @@ def test_value_access_with_confmod(self, basedir):
8081
assert path.purebasename.startswith("conftest")
8182

8283

83-
def test_conftest_in_nonpkg_with_init(tmpdir):
84+
def test_conftest_in_nonpkg_with_init(tmpdir, _sys_snapshot):
8485
tmpdir.ensure("adir-1.0/conftest.py").write("a=1 ; Directory = 3")
8586
tmpdir.ensure("adir-1.0/b/conftest.py").write("b=2 ; a = 1.5")
8687
tmpdir.ensure("adir-1.0/b/__init__.py")

0 commit comments

Comments
 (0)