Merge pull request #4075 from nicoddemus/dynamic-fixturenames
Fix request.fixturenames to return fixtures created dynamically
This commit is contained in:
commit
a1208f5631
|
@ -0,0 +1 @@
|
||||||
|
``request.fixturenames`` now correctly returns the name of fixtures created by ``request.getfixturevalue()``.
|
|
@ -359,8 +359,10 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fixturenames(self):
|
def fixturenames(self):
|
||||||
# backward incompatible note: now a readonly property
|
"""names of all active fixtures in this request"""
|
||||||
return list(self._pyfuncitem._fixtureinfo.names_closure)
|
result = list(self._pyfuncitem._fixtureinfo.names_closure)
|
||||||
|
result.extend(set(self._fixture_defs).difference(result))
|
||||||
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def node(self):
|
def node(self):
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dynamic():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def a(request):
|
||||||
|
request.getfixturevalue("dynamic")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def b(a):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test(b, request):
|
||||||
|
assert request.fixturenames == ["b", "request", "a", "dynamic"]
|
|
@ -756,6 +756,12 @@ class TestRequestBasic(object):
|
||||||
reprec = testdir.inline_run()
|
reprec = testdir.inline_run()
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
|
def test_request_fixturenames_dynamic_fixture(self, testdir):
|
||||||
|
"""Regression test for #3057"""
|
||||||
|
testdir.copy_example("fixtures/test_getfixturevalue_dynamic.py")
|
||||||
|
result = testdir.runpytest()
|
||||||
|
result.stdout.fnmatch_lines("*1 passed*")
|
||||||
|
|
||||||
def test_funcargnames_compatattr(self, testdir):
|
def test_funcargnames_compatattr(self, testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue