Merge pull request #4123 from blueyed/clarify
tests: clarify/document/harden acceptance tests
This commit is contained in:
commit
c27c8f41a8
|
@ -12,6 +12,13 @@ import pytest
|
||||||
from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
|
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):
|
class TestGeneralUsage(object):
|
||||||
def test_config_error(self, testdir):
|
def test_config_error(self, testdir):
|
||||||
testdir.copy_example("conftest_usageerror/conftest.py")
|
testdir.copy_example("conftest_usageerror/conftest.py")
|
||||||
|
@ -570,14 +577,8 @@ class TestInvocationVariants(object):
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
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")
|
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;
|
# 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
|
# no idea why only pypy and not normal python warn about it here
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
|
@ -586,7 +587,7 @@ class TestInvocationVariants(object):
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines(["*2 passed*"])
|
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)
|
result = testdir.runpytest("--pyargs", "tpkg.test_missing", syspathinsert=True)
|
||||||
assert result.ret != 0
|
assert result.ret != 0
|
||||||
result.stderr.fnmatch_lines(["*not*found*test_missing*"])
|
result.stderr.fnmatch_lines(["*not*found*test_missing*"])
|
||||||
|
@ -626,18 +627,13 @@ class TestInvocationVariants(object):
|
||||||
# ├── __init__.py
|
# ├── __init__.py
|
||||||
# └── test_world.py
|
# └── test_world.py
|
||||||
|
|
||||||
def join_pythonpath(*dirs):
|
# NOTE: the different/reversed ordering is intentional here.
|
||||||
cur = os.environ.get("PYTHONPATH")
|
monkeypatch.setenv("PYTHONPATH", prepend_pythonpath(*search_path))
|
||||||
if cur:
|
|
||||||
dirs += (cur,)
|
|
||||||
return os.pathsep.join(str(p) for p in dirs)
|
|
||||||
|
|
||||||
monkeypatch.setenv("PYTHONPATH", join_pythonpath(*search_path))
|
|
||||||
for p in search_path:
|
for p in search_path:
|
||||||
monkeypatch.syspath_prepend(p)
|
monkeypatch.syspath_prepend(p)
|
||||||
|
|
||||||
# mixed module and filenames:
|
# mixed module and filenames:
|
||||||
os.chdir("world")
|
monkeypatch.chdir("world")
|
||||||
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world")
|
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world")
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
|
@ -688,8 +684,6 @@ class TestInvocationVariants(object):
|
||||||
pytest.skip(six.text_type(e.args[0]))
|
pytest.skip(six.text_type(e.args[0]))
|
||||||
monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
|
monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
|
||||||
|
|
||||||
search_path = ["lib", os.path.join("local", "lib")]
|
|
||||||
|
|
||||||
dirname = "lib"
|
dirname = "lib"
|
||||||
d = testdir.mkdir(dirname)
|
d = testdir.mkdir(dirname)
|
||||||
foo = d.mkdir("foo")
|
foo = d.mkdir("foo")
|
||||||
|
@ -722,13 +716,9 @@ class TestInvocationVariants(object):
|
||||||
# ├── conftest.py
|
# ├── conftest.py
|
||||||
# └── test_bar.py
|
# └── test_bar.py
|
||||||
|
|
||||||
def join_pythonpath(*dirs):
|
# NOTE: the different/reversed ordering is intentional here.
|
||||||
cur = os.getenv("PYTHONPATH")
|
search_path = ["lib", os.path.join("local", "lib")]
|
||||||
if cur:
|
monkeypatch.setenv("PYTHONPATH", prepend_pythonpath(*search_path))
|
||||||
dirs += (cur,)
|
|
||||||
return os.pathsep.join(str(p) for p in dirs)
|
|
||||||
|
|
||||||
monkeypatch.setenv("PYTHONPATH", join_pythonpath(*search_path))
|
|
||||||
for p in search_path:
|
for p in search_path:
|
||||||
monkeypatch.syspath_prepend(p)
|
monkeypatch.syspath_prepend(p)
|
||||||
|
|
||||||
|
@ -738,8 +728,8 @@ class TestInvocationVariants(object):
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"*lib/foo/bar/test_bar.py::test_bar*PASSED*",
|
"*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_other PASSED*",
|
||||||
"*2 passed*",
|
"*2 passed*",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue