From 81426c3d196028d77fb1bcbcccca8b9d83ea79a3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 10 Oct 2018 18:02:37 +0200 Subject: [PATCH 1/2] tests: harden test_cmdline_python_package_symlink --- testing/acceptance_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index b0d0a7e61..fde25549d 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -738,8 +738,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*", ] ) From 6bf4692c7d8100b19dc0178764398edbd7803701 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 12 Oct 2018 15:15:35 +0200 Subject: [PATCH 2/2] acceptance_test: clarify/document/fix tests Ref: https://github.com/pytest-dev/pytest/commit/e2e6e317118d6d15ccdf6f6708a48c08d85cbc25#r30863971 --- testing/acceptance_test.py | 40 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index fde25549d..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)