Merge pull request #5094 from blueyed/merge-master
Merge master into festures
This commit is contained in:
		
						commit
						97cd5f0deb
					
				|  | @ -344,6 +344,15 @@ def testdir(request, tmpdir_factory): | ||||||
|     return Testdir(request, tmpdir_factory) |     return Testdir(request, tmpdir_factory) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.fixture | ||||||
|  | def _sys_snapshot(): | ||||||
|  |     snappaths = SysPathsSnapshot() | ||||||
|  |     snapmods = SysModulesSnapshot() | ||||||
|  |     yield | ||||||
|  |     snapmods.restore() | ||||||
|  |     snappaths.restore() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @pytest.fixture | @pytest.fixture | ||||||
| def _config_for_test(): | def _config_for_test(): | ||||||
|     from _pytest.config import get_config |     from _pytest.config import get_config | ||||||
|  |  | ||||||
|  | @ -485,7 +485,7 @@ class TestGeneralUsage(object): | ||||||
|             ["*source code not available*", "E*fixture 'invalid_fixture' not found"] |             ["*source code not available*", "E*fixture 'invalid_fixture' not found"] | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|     def test_plugins_given_as_strings(self, tmpdir, monkeypatch): |     def test_plugins_given_as_strings(self, tmpdir, monkeypatch, _sys_snapshot): | ||||||
|         """test that str values passed to main() as `plugins` arg |         """test that str values passed to main() as `plugins` arg | ||||||
|         are interpreted as module names to be imported and registered. |         are interpreted as module names to be imported and registered. | ||||||
|         #855. |         #855. | ||||||
|  |  | ||||||
|  | @ -441,7 +441,7 @@ def test_match_raises_error(testdir): | ||||||
| 
 | 
 | ||||||
| class TestFormattedExcinfo(object): | class TestFormattedExcinfo(object): | ||||||
|     @pytest.fixture |     @pytest.fixture | ||||||
|     def importasmod(self, request): |     def importasmod(self, request, _sys_snapshot): | ||||||
|         def importasmod(source): |         def importasmod(source): | ||||||
|             source = textwrap.dedent(source) |             source = textwrap.dedent(source) | ||||||
|             tmpdir = request.getfixturevalue("tmpdir") |             tmpdir = request.getfixturevalue("tmpdir") | ||||||
|  |  | ||||||
|  | @ -410,7 +410,7 @@ def test_deindent(): | ||||||
|     assert lines == ["def f():", "    def g():", "        pass"] |     assert lines == ["def f():", "    def g():", "        pass"] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_source_of_class_at_eof_without_newline(tmpdir): | def test_source_of_class_at_eof_without_newline(tmpdir, _sys_snapshot): | ||||||
|     # this test fails because the implicit inspect.getsource(A) below |     # this test fails because the implicit inspect.getsource(A) below | ||||||
|     # does not return the "x = 1" last line. |     # does not return the "x = 1" last line. | ||||||
|     source = _pytest._code.Source( |     source = _pytest._code.Source( | ||||||
|  |  | ||||||
|  | @ -436,7 +436,7 @@ class TestConfigAPI(object): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestConfigFromdictargs(object): | class TestConfigFromdictargs(object): | ||||||
|     def test_basic_behavior(self): |     def test_basic_behavior(self, _sys_snapshot): | ||||||
|         from _pytest.config import Config |         from _pytest.config import Config | ||||||
| 
 | 
 | ||||||
|         option_dict = {"verbose": 444, "foo": "bar", "capture": "no"} |         option_dict = {"verbose": 444, "foo": "bar", "capture": "no"} | ||||||
|  | @ -450,7 +450,7 @@ class TestConfigFromdictargs(object): | ||||||
|         assert config.option.capture == "no" |         assert config.option.capture == "no" | ||||||
|         assert config.args == args |         assert config.args == args | ||||||
| 
 | 
 | ||||||
|     def test_origargs(self): |     def test_origargs(self, _sys_snapshot): | ||||||
|         """Show that fromdictargs can handle args in their "orig" format""" |         """Show that fromdictargs can handle args in their "orig" format""" | ||||||
|         from _pytest.config import Config |         from _pytest.config import Config | ||||||
| 
 | 
 | ||||||
|  | @ -1057,7 +1057,7 @@ class TestOverrideIniArgs(object): | ||||||
|             assert rootdir == tmpdir |             assert rootdir == tmpdir | ||||||
|             assert inifile is None |             assert inifile is None | ||||||
| 
 | 
 | ||||||
|     def test_addopts_before_initini(self, monkeypatch, _config_for_test): |     def test_addopts_before_initini(self, monkeypatch, _config_for_test, _sys_snapshot): | ||||||
|         cache_dir = ".custom_cache" |         cache_dir = ".custom_cache" | ||||||
|         monkeypatch.setenv("PYTEST_ADDOPTS", "-o cache_dir=%s" % cache_dir) |         monkeypatch.setenv("PYTEST_ADDOPTS", "-o cache_dir=%s" % cache_dir) | ||||||
|         config = _config_for_test |         config = _config_for_test | ||||||
|  | @ -1092,7 +1092,7 @@ class TestOverrideIniArgs(object): | ||||||
|         ) |         ) | ||||||
|         assert result.ret == _pytest.main.EXIT_USAGEERROR |         assert result.ret == _pytest.main.EXIT_USAGEERROR | ||||||
| 
 | 
 | ||||||
|     def test_override_ini_does_not_contain_paths(self, _config_for_test): |     def test_override_ini_does_not_contain_paths(self, _config_for_test, _sys_snapshot): | ||||||
|         """Check that -o no longer swallows all options after it (#3103)""" |         """Check that -o no longer swallows all options after it (#3103)""" | ||||||
|         config = _config_for_test |         config = _config_for_test | ||||||
|         config._preparse(["-o", "cache_dir=/cache", "/some/test/path"]) |         config._preparse(["-o", "cache_dir=/cache", "/some/test/path"]) | ||||||
|  |  | ||||||
|  | @ -13,17 +13,6 @@ from _pytest.main import EXIT_OK | ||||||
| from _pytest.main import EXIT_USAGEERROR | from _pytest.main import EXIT_USAGEERROR | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.fixture(scope="module", params=["global", "inpackage"]) |  | ||||||
| def basedir(request, tmpdir_factory): |  | ||||||
|     tmpdir = tmpdir_factory.mktemp("basedir", numbered=True) |  | ||||||
|     tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3") |  | ||||||
|     tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5") |  | ||||||
|     if request.param == "inpackage": |  | ||||||
|         tmpdir.ensure("adir/__init__.py") |  | ||||||
|         tmpdir.ensure("adir/b/__init__.py") |  | ||||||
|     return tmpdir |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def ConftestWithSetinitial(path): | def ConftestWithSetinitial(path): | ||||||
|     conftest = PytestPluginManager() |     conftest = PytestPluginManager() | ||||||
|     conftest_setinitial(conftest, [path]) |     conftest_setinitial(conftest, [path]) | ||||||
|  | @ -41,7 +30,19 @@ def conftest_setinitial(conftest, args, confcutdir=None): | ||||||
|     conftest._set_initial_conftests(Namespace()) |     conftest._set_initial_conftests(Namespace()) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @pytest.mark.usefixtures("_sys_snapshot") | ||||||
| class TestConftestValueAccessGlobal(object): | class TestConftestValueAccessGlobal(object): | ||||||
|  |     @pytest.fixture(scope="module", params=["global", "inpackage"]) | ||||||
|  |     def basedir(self, request, tmpdir_factory): | ||||||
|  |         tmpdir = tmpdir_factory.mktemp("basedir", numbered=True) | ||||||
|  |         tmpdir.ensure("adir/conftest.py").write("a=1 ; Directory = 3") | ||||||
|  |         tmpdir.ensure("adir/b/conftest.py").write("b=2 ; a = 1.5") | ||||||
|  |         if request.param == "inpackage": | ||||||
|  |             tmpdir.ensure("adir/__init__.py") | ||||||
|  |             tmpdir.ensure("adir/b/__init__.py") | ||||||
|  | 
 | ||||||
|  |         yield tmpdir | ||||||
|  | 
 | ||||||
|     def test_basic_init(self, basedir): |     def test_basic_init(self, basedir): | ||||||
|         conftest = PytestPluginManager() |         conftest = PytestPluginManager() | ||||||
|         p = basedir.join("adir") |         p = basedir.join("adir") | ||||||
|  | @ -49,10 +50,10 @@ class TestConftestValueAccessGlobal(object): | ||||||
| 
 | 
 | ||||||
|     def test_immediate_initialiation_and_incremental_are_the_same(self, basedir): |     def test_immediate_initialiation_and_incremental_are_the_same(self, basedir): | ||||||
|         conftest = PytestPluginManager() |         conftest = PytestPluginManager() | ||||||
|         len(conftest._dirpath2confmods) |         assert not len(conftest._dirpath2confmods) | ||||||
|         conftest._getconftestmodules(basedir) |         conftest._getconftestmodules(basedir) | ||||||
|         snap1 = len(conftest._dirpath2confmods) |         snap1 = len(conftest._dirpath2confmods) | ||||||
|         # assert len(conftest._dirpath2confmods) == snap1 + 1 |         assert snap1 == 1 | ||||||
|         conftest._getconftestmodules(basedir.join("adir")) |         conftest._getconftestmodules(basedir.join("adir")) | ||||||
|         assert len(conftest._dirpath2confmods) == snap1 + 1 |         assert len(conftest._dirpath2confmods) == snap1 + 1 | ||||||
|         conftest._getconftestmodules(basedir.join("b")) |         conftest._getconftestmodules(basedir.join("b")) | ||||||
|  | @ -80,7 +81,7 @@ class TestConftestValueAccessGlobal(object): | ||||||
|         assert path.purebasename.startswith("conftest") |         assert path.purebasename.startswith("conftest") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_conftest_in_nonpkg_with_init(tmpdir): | def test_conftest_in_nonpkg_with_init(tmpdir, _sys_snapshot): | ||||||
|     tmpdir.ensure("adir-1.0/conftest.py").write("a=1 ; Directory = 3") |     tmpdir.ensure("adir-1.0/conftest.py").write("a=1 ; Directory = 3") | ||||||
|     tmpdir.ensure("adir-1.0/b/conftest.py").write("b=2 ; a = 1.5") |     tmpdir.ensure("adir-1.0/b/conftest.py").write("b=2 ; a = 1.5") | ||||||
|     tmpdir.ensure("adir-1.0/b/__init__.py") |     tmpdir.ensure("adir-1.0/b/__init__.py") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue