move conftest visibility tests and their setup into a class, accomodates @nicoddemus 's comment
--HG-- branch : issue616
This commit is contained in:
parent
d73e689991
commit
28c2327f73
|
@ -259,88 +259,87 @@ def test_conftest_found_with_double_dash(testdir):
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
# conftest visibility, related to issue616
|
class TestConftestVisibility:
|
||||||
|
def _setup_tree(self, testdir): # for issue616
|
||||||
|
# example mostly taken from:
|
||||||
|
# https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html
|
||||||
|
runner = testdir.mkdir("empty")
|
||||||
|
package = testdir.mkdir("package")
|
||||||
|
|
||||||
def _setup_tree(testdir):
|
package.join("conftest.py").write(dedent("""\
|
||||||
# example mostly taken from:
|
import pytest
|
||||||
# https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html
|
@pytest.fixture
|
||||||
runner = testdir.mkdir("empty")
|
def fxtr():
|
||||||
package = testdir.mkdir("package")
|
return "from-package"
|
||||||
|
"""))
|
||||||
|
package.join("test_pkgroot.py").write(dedent("""\
|
||||||
|
def test_pkgroot(fxtr):
|
||||||
|
assert fxtr == "from-package"
|
||||||
|
"""))
|
||||||
|
|
||||||
package.join("conftest.py").write(dedent("""\
|
swc = package.mkdir("swc")
|
||||||
import pytest
|
swc.join("__init__.py").ensure()
|
||||||
@pytest.fixture
|
swc.join("conftest.py").write(dedent("""\
|
||||||
def fxtr():
|
import pytest
|
||||||
return "from-package"
|
@pytest.fixture
|
||||||
"""))
|
def fxtr():
|
||||||
package.join("test_pkgroot.py").write(dedent("""\
|
return "from-swc"
|
||||||
def test_pkgroot(fxtr):
|
"""))
|
||||||
assert fxtr == "from-package"
|
swc.join("test_with_conftest.py").write(dedent("""\
|
||||||
"""))
|
def test_with_conftest(fxtr):
|
||||||
|
assert fxtr == "from-swc"
|
||||||
|
|
||||||
swc = package.mkdir("swc")
|
"""))
|
||||||
swc.join("__init__.py").ensure()
|
|
||||||
swc.join("conftest.py").write(dedent("""\
|
|
||||||
import pytest
|
|
||||||
@pytest.fixture
|
|
||||||
def fxtr():
|
|
||||||
return "from-swc"
|
|
||||||
"""))
|
|
||||||
swc.join("test_with_conftest.py").write(dedent("""\
|
|
||||||
def test_with_conftest(fxtr):
|
|
||||||
assert fxtr == "from-swc"
|
|
||||||
|
|
||||||
"""))
|
snc = package.mkdir("snc")
|
||||||
|
snc.join("__init__.py").ensure()
|
||||||
|
snc.join("test_no_conftest.py").write(dedent("""\
|
||||||
|
def test_no_conftest(fxtr):
|
||||||
|
assert fxtr == "from-package" # No local conftest.py, so should
|
||||||
|
# use value from parent dir's
|
||||||
|
|
||||||
snc = package.mkdir("snc")
|
"""))
|
||||||
snc.join("__init__.py").ensure()
|
print ("created directory structure:")
|
||||||
snc.join("test_no_conftest.py").write(dedent("""\
|
for x in testdir.tmpdir.visit():
|
||||||
def test_no_conftest(fxtr):
|
print (" " + x.relto(testdir.tmpdir))
|
||||||
assert fxtr == "from-package" # No local conftest.py, so should
|
|
||||||
# use value from parent dir's
|
|
||||||
|
|
||||||
"""))
|
return {
|
||||||
print ("created directory structure:")
|
"runner": runner,
|
||||||
for x in testdir.tmpdir.visit():
|
"package": package,
|
||||||
print (" " + x.relto(testdir.tmpdir))
|
"swc": swc,
|
||||||
|
"snc": snc}
|
||||||
|
|
||||||
return {
|
# N.B.: "swc" stands for "subdir with conftest.py"
|
||||||
"runner": runner,
|
# "snc" stands for "subdir no [i.e. without] conftest.py"
|
||||||
"package": package,
|
@pytest.mark.parametrize("chdir,testarg,expect_ntests_passed", [
|
||||||
"swc": swc,
|
("runner", "..", 3),
|
||||||
"snc": snc}
|
("package", "..", 3),
|
||||||
|
("swc", "../..", 3),
|
||||||
|
("snc", "../..", 3),
|
||||||
|
|
||||||
# N.B.: "swc" stands for "subdir with conftest.py"
|
("runner", "../package", 3),
|
||||||
# "snc" stands for "subdir no [i.e. without] conftest.py"
|
("package", ".", 3),
|
||||||
@pytest.mark.parametrize("chdir,testarg,expect_ntests_passed", [
|
("swc", "..", 3),
|
||||||
("runner", "..", 3),
|
("snc", "..", 3),
|
||||||
("package", "..", 3),
|
|
||||||
("swc", "../..", 3),
|
|
||||||
("snc", "../..", 3),
|
|
||||||
|
|
||||||
("runner", "../package", 3),
|
("runner", "../package/swc", 1),
|
||||||
("package", ".", 3),
|
("package", "./swc", 1),
|
||||||
("swc", "..", 3),
|
("swc", ".", 1),
|
||||||
("snc", "..", 3),
|
("snc", "../swc", 1),
|
||||||
|
|
||||||
("runner", "../package/swc", 1),
|
("runner", "../package/snc", 1),
|
||||||
("package", "./swc", 1),
|
("package", "./snc", 1),
|
||||||
("swc", ".", 1),
|
("swc", "../snc", 1),
|
||||||
("snc", "../swc", 1),
|
("snc", ".", 1),
|
||||||
|
])
|
||||||
("runner", "../package/snc", 1),
|
@pytest.mark.issue616
|
||||||
("package", "./snc", 1),
|
def test_parsefactories_relative_node_ids(
|
||||||
("swc", "../snc", 1),
|
self, testdir, chdir,testarg, expect_ntests_passed):
|
||||||
("snc", ".", 1),
|
dirs = self._setup_tree(testdir)
|
||||||
])
|
print("pytest run in cwd: %s" %(
|
||||||
@pytest.mark.issue616
|
dirs[chdir].relto(testdir.tmpdir)))
|
||||||
def test_parsefactories_relative_node_ids(
|
print("pytestarg : %s" %(testarg))
|
||||||
testdir, chdir,testarg, expect_ntests_passed):
|
print("expected pass : %s" %(expect_ntests_passed))
|
||||||
dirs = _setup_tree(testdir)
|
with dirs[chdir].as_cwd():
|
||||||
print("pytest run in cwd: %s" %(
|
reprec = testdir.inline_run(testarg, "-q", "--traceconfig")
|
||||||
dirs[chdir].relto(testdir.tmpdir)))
|
reprec.assertoutcome(passed=expect_ntests_passed)
|
||||||
print("pytestarg : %s" %(testarg))
|
|
||||||
print("expected pass : %s" %(expect_ntests_passed))
|
|
||||||
with dirs[chdir].as_cwd():
|
|
||||||
reprec = testdir.inline_run(testarg, "-q", "--traceconfig")
|
|
||||||
reprec.assertoutcome(passed=expect_ntests_passed)
|
|
||||||
|
|
Loading…
Reference in New Issue