Skip to content

Commit

Permalink
Merge 70c7273 into e712adc
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Oct 3, 2018
2 parents e712adc + 70c7273 commit ac5e6e4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/3057.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``request.fixturenames`` now correctly returns the name of fixtures created by ``request.getfixturevalue()``.
6 changes: 4 additions & 2 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ def __init__(self, pyfuncitem):

@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):
Expand Down
20 changes: 20 additions & 0 deletions testing/example_scripts/fixtures/test_getfixturevalue_dynamic.py
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ def test_function(request, farg):
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(
"""
Expand Down

0 comments on commit ac5e6e4

Please sign in to comment.