Merge pull request #4075 from nicoddemus/dynamic-fixturenames

Fix request.fixturenames to return fixtures created dynamically
This commit is contained in:
Bruno Oliveira 2018-10-04 09:21:23 -03:00 committed by GitHub
commit a1208f5631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1 @@
``request.fixturenames`` now correctly returns the name of fixtures created by ``request.getfixturevalue()``.

View File

@ -359,8 +359,10 @@ class FixtureRequest(FuncargnamesCompatAttr):
@property
def fixturenames(self):
# backward incompatible note: now a readonly property
return list(self._pyfuncitem._fixtureinfo.names_closure)
"""names of all active fixtures in this request"""
result = list(self._pyfuncitem._fixtureinfo.names_closure)
result.extend(set(self._fixture_defs).difference(result))
return result
@property
def node(self):

View File

@ -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"]

View File

@ -756,6 +756,12 @@ class TestRequestBasic(object):
reprec = testdir.inline_run()
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):
testdir.makepyfile(
"""