Merged in paylogic/pytest/multi-level-fixture-deps-override (pull request #83)
When overridden, fixture's dependencies are called from all levels of folder structure
This commit is contained in:
commit
ce0af892aa
|
@ -1556,8 +1556,7 @@ class FixtureManager:
|
||||||
fixturedefs = self.getfixturedefs(argname, parentid)
|
fixturedefs = self.getfixturedefs(argname, parentid)
|
||||||
arg2fixturedefs[argname] = fixturedefs
|
arg2fixturedefs[argname] = fixturedefs
|
||||||
if fixturedefs is not None:
|
if fixturedefs is not None:
|
||||||
for fixturedef in fixturedefs:
|
merge(fixturedefs[-1].argnames)
|
||||||
merge(fixturedef.argnames)
|
|
||||||
return fixturenames_closure, arg2fixturedefs
|
return fixturenames_closure, arg2fixturedefs
|
||||||
|
|
||||||
def pytest_generate_tests(self, metafunc):
|
def pytest_generate_tests(self, metafunc):
|
||||||
|
|
|
@ -215,3 +215,40 @@ def test_conftest_import_order(testdir, monkeypatch):
|
||||||
conftest = Conftest()
|
conftest = Conftest()
|
||||||
monkeypatch.setattr(conftest, 'importconftest', impct)
|
monkeypatch.setattr(conftest, 'importconftest', impct)
|
||||||
assert conftest.getconftestmodules(sub) == [ct1, ct2]
|
assert conftest.getconftestmodules(sub) == [ct1, ct2]
|
||||||
|
|
||||||
|
|
||||||
|
def test_fixture_dependency(testdir, monkeypatch):
|
||||||
|
ct1 = testdir.makeconftest("")
|
||||||
|
ct1 = testdir.makepyfile("__init__.py")
|
||||||
|
ct1.write("")
|
||||||
|
sub = testdir.mkdir("sub")
|
||||||
|
sub.join("__init__.py").write("")
|
||||||
|
sub.join("conftest.py").write(py.std.textwrap.dedent("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def not_needed():
|
||||||
|
assert False, "Should not be called!"
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def foo():
|
||||||
|
assert False, "Should not be called!"
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def bar(foo):
|
||||||
|
return 'bar'
|
||||||
|
"""))
|
||||||
|
subsub = sub.mkdir("subsub")
|
||||||
|
subsub.join("__init__.py").write("")
|
||||||
|
subsub.join("test_bar.py").write(py.std.textwrap.dedent("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def bar():
|
||||||
|
return 'sub bar'
|
||||||
|
|
||||||
|
def test_event_fixture(bar):
|
||||||
|
assert bar == 'sub bar'
|
||||||
|
"""))
|
||||||
|
result = testdir.runpytest("sub")
|
||||||
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||||
|
|
Loading…
Reference in New Issue