Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 17 additions & 27 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
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")
Expand Down Expand Up @@ -570,14 +577,8 @@ def test_cmdline_python_package(self, testdir, monkeypatch):
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():
Expand All @@ -586,7 +587,7 @@ def join_pythonpath(what):
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*"])
Expand Down Expand Up @@ -626,18 +627,13 @@ def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
# ├── __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(
Expand Down Expand Up @@ -688,8 +684,6 @@ def test_cmdline_python_package_symlink(self, testdir, monkeypatch):
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")
Expand Down Expand Up @@ -722,13 +716,9 @@ def test_cmdline_python_package_symlink(self, testdir, monkeypatch):
# ├── 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)

Expand All @@ -738,8 +728,8 @@ def join_pythonpath(*dirs):
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*",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #4108 this will change to:

lib/foo/bar/test_bar.py::test_bar <- local/lib/foo/bar/test_bar.py PASSED [ 50%]
lib/foo/bar/test_bar.py::test_other <- local/lib/foo/bar/test_bar.py PASSED [100%]

"*2 passed*",
]
)
Expand Down