diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index b0d0a7e61..29b4f2b42 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -12,6 +12,13 @@ import pytest from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR +def prepend_pythonpath(*dirs): + cur = os.getenv("PYTHONPATH") + if cur: + dirs += (cur,) + return os.pathsep.join(str(p) for p in dirs) + + class TestGeneralUsage(object): def test_config_error(self, testdir): testdir.copy_example("conftest_usageerror/conftest.py") @@ -570,14 +577,8 @@ class TestInvocationVariants(object): assert result.ret == 0 result.stdout.fnmatch_lines(["*1 passed*"]) - def join_pythonpath(what): - cur = os.environ.get("PYTHONPATH") - if cur: - return str(what) + os.pathsep + cur - return what - empty_package = testdir.mkpydir("empty_package") - monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(empty_package))) + monkeypatch.setenv("PYTHONPATH", str(empty_package), prepend=os.pathsep) # the path which is not a package raises a warning on pypy; # no idea why only pypy and not normal python warn about it here with warnings.catch_warnings(): @@ -586,7 +587,7 @@ class TestInvocationVariants(object): assert result.ret == 0 result.stdout.fnmatch_lines(["*2 passed*"]) - monkeypatch.setenv("PYTHONPATH", str(join_pythonpath(testdir))) + monkeypatch.setenv("PYTHONPATH", str(testdir), prepend=os.pathsep) result = testdir.runpytest("--pyargs", "tpkg.test_missing", syspathinsert=True) assert result.ret != 0 result.stderr.fnmatch_lines(["*not*found*test_missing*"]) @@ -626,18 +627,13 @@ class TestInvocationVariants(object): # ├── __init__.py # └── test_world.py - def join_pythonpath(*dirs): - cur = os.environ.get("PYTHONPATH") - if cur: - dirs += (cur,) - return os.pathsep.join(str(p) for p in dirs) - - monkeypatch.setenv("PYTHONPATH", join_pythonpath(*search_path)) + # NOTE: the different/reversed ordering is intentional here. + monkeypatch.setenv("PYTHONPATH", prepend_pythonpath(*search_path)) for p in search_path: monkeypatch.syspath_prepend(p) # mixed module and filenames: - os.chdir("world") + monkeypatch.chdir("world") result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world") assert result.ret == 0 result.stdout.fnmatch_lines( @@ -688,8 +684,6 @@ class TestInvocationVariants(object): pytest.skip(six.text_type(e.args[0])) monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False) - search_path = ["lib", os.path.join("local", "lib")] - dirname = "lib" d = testdir.mkdir(dirname) foo = d.mkdir("foo") @@ -722,13 +716,9 @@ class TestInvocationVariants(object): # ├── conftest.py # └── test_bar.py - def join_pythonpath(*dirs): - cur = os.getenv("PYTHONPATH") - if cur: - dirs += (cur,) - return os.pathsep.join(str(p) for p in dirs) - - monkeypatch.setenv("PYTHONPATH", join_pythonpath(*search_path)) + # NOTE: the different/reversed ordering is intentional here. + search_path = ["lib", os.path.join("local", "lib")] + monkeypatch.setenv("PYTHONPATH", prepend_pythonpath(*search_path)) for p in search_path: monkeypatch.syspath_prepend(p) @@ -738,8 +728,8 @@ class TestInvocationVariants(object): assert result.ret == 0 result.stdout.fnmatch_lines( [ - "*lib/foo/bar/test_bar.py::test_bar*PASSED*", - "*lib/foo/bar/test_bar.py::test_other*PASSED*", + "*lib/foo/bar/test_bar.py::test_bar PASSED*", + "*lib/foo/bar/test_bar.py::test_other PASSED*", "*2 passed*", ] )