Skip to content

Commit 0c74f4b

Browse files
committed
issue1625, name getfuncargvalue to getfixturevalue
1 parent 5d8d1db commit 0c74f4b

File tree

9 files changed

+35
-28
lines changed

9 files changed

+35
-28
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
is specified on the command line together with the ``--pyargs``
1818
option. Thanks to `@taschini`_ for the PR (`#1597`_).
1919

20+
* Rename ``getfuncargvalue`` to ``getfixturevalue``. `getfuncargvalue`
21+
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
22+
for PR (`#1626`_).
23+
2024
*
2125

2226
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
2327
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
2428
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
29+
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
2530

2631
.. _@graingert: https://github.com/graingert
2732
.. _@taschini: https://github.com/taschini

_pytest/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self, name, parent, runner=None, dtest=None):
7070
def setup(self):
7171
if self.dtest is not None:
7272
self.fixture_request = _setup_fixtures(self)
73-
globs = dict(getfixture=self.fixture_request.getfuncargvalue)
73+
globs = dict(getfixture=self.fixture_request.getfixturevalue)
7474
self.dtest.globs.update(globs)
7575

7676
def runtest(self):

_pytest/python.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ def _getnextfixturedef(self, argname):
14691469
fixturedefs = self._arg2fixturedefs.get(argname, None)
14701470
if fixturedefs is None:
14711471
# we arrive here because of a a dynamic call to
1472-
# getfuncargvalue(argname) usage which was naturally
1472+
# getfixturevalue(argname) usage which was naturally
14731473
# not known at parsing/collection time
14741474
fixturedefs = self._fixturemanager.getfixturedefs(
14751475
argname, self._pyfuncitem.parent.nodeid)
@@ -1564,7 +1564,7 @@ def _fillfixtures(self):
15641564
fixturenames = getattr(item, "fixturenames", self.fixturenames)
15651565
for argname in fixturenames:
15661566
if argname not in item.funcargs:
1567-
item.funcargs[argname] = self.getfuncargvalue(argname)
1567+
item.funcargs[argname] = self.getfixturevalue(argname)
15681568

15691569
def cached_setup(self, setup, teardown=None, scope="module", extrakey=None):
15701570
""" (deprecated) Return a testing resource managed by ``setup`` &
@@ -1598,17 +1598,19 @@ def finalizer():
15981598
self._addfinalizer(finalizer, scope=scope)
15991599
return val
16001600

1601-
def getfuncargvalue(self, argname):
1602-
""" Dynamically retrieve a named fixture function argument.
1601+
def getfixturevalue(self, argname):
1602+
""" Dynamically run a named fixture function.
16031603
1604-
As of pytest-2.3, it is easier and usually better to access other
1605-
fixture values by stating it as an input argument in the fixture
1606-
function. If you only can decide about using another fixture at test
1604+
Declaring fixtures via function argument is recommended where possible.
1605+
But if you can only decide whether to use another fixture at test
16071606
setup time, you may use this function to retrieve it inside a fixture
1608-
function body.
1607+
or test function body.
16091608
"""
16101609
return self._get_active_fixturedef(argname).cached_result[0]
16111610

1611+
# now deprecated
1612+
getfuncargvalue = getfixturevalue
1613+
16121614
def _get_active_fixturedef(self, argname):
16131615
try:
16141616
return self._fixturedefs[argname]
@@ -1624,7 +1626,7 @@ class PseudoFixtureDef:
16241626
raise
16251627
# remove indent to prevent the python3 exception
16261628
# from leaking into the call
1627-
result = self._getfuncargvalue(fixturedef)
1629+
result = self._getfixturevalue(fixturedef)
16281630
self._funcargs[argname] = result
16291631
self._fixturedefs[argname] = fixturedef
16301632
return fixturedef
@@ -1640,7 +1642,7 @@ def _get_fixturestack(self):
16401642
l.append(fixturedef)
16411643
current = current._parent_request
16421644

1643-
def _getfuncargvalue(self, fixturedef):
1645+
def _getfixturevalue(self, fixturedef):
16441646
# prepare a subrequest object before calling fixture function
16451647
# (latter managed by fixturedef)
16461648
argname = fixturedef.argname

doc/en/genapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def docmethod(self, method):
3232

3333
def pytest_funcarg__a(request):
3434
with Writer("request") as writer:
35-
writer.docmethod(request.getfuncargvalue)
35+
writer.docmethod(request.getfixturevalue)
3636
writer.docmethod(request.cached_setup)
3737
writer.docmethod(request.addfinalizer)
3838
writer.docmethod(request.applymarker)

testing/code/test_excinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class TestFormattedExcinfo:
327327
def pytest_funcarg__importasmod(self, request):
328328
def importasmod(source):
329329
source = _pytest._code.Source(source)
330-
tmpdir = request.getfuncargvalue("tmpdir")
330+
tmpdir = request.getfixturevalue("tmpdir")
331331
modpath = tmpdir.join("mod.py")
332332
tmpdir.ensure("__init__.py")
333333
modpath.write(source)

testing/python/fixture.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ def test_conftest_funcargs_only_available_in_subdir(self, testdir):
9393
sub1.join("conftest.py").write(_pytest._code.Source("""
9494
import pytest
9595
def pytest_funcarg__arg1(request):
96-
pytest.raises(Exception, "request.getfuncargvalue('arg2')")
96+
pytest.raises(Exception, "request.getfixturevalue('arg2')")
9797
"""))
9898
sub2.join("conftest.py").write(_pytest._code.Source("""
9999
import pytest
100100
def pytest_funcarg__arg2(request):
101-
pytest.raises(Exception, "request.getfuncargvalue('arg1')")
101+
pytest.raises(Exception, "request.getfixturevalue('arg1')")
102102
"""))
103103

104104
sub1.join("test_in_sub1.py").write("def test_1(arg1): pass")
@@ -442,7 +442,7 @@ def pytest_funcarg__something(request):
442442
""")
443443
testdir.makepyfile("""
444444
def pytest_funcarg__something(request):
445-
return request.getfuncargvalue("something") + 1
445+
return request.getfixturevalue("something") + 1
446446
def test_func(something):
447447
assert something == 2
448448
""")
@@ -458,14 +458,14 @@ def pytest_funcarg__other(request):
458458
def test_func(something): pass
459459
""")
460460
req = item._request
461-
pytest.raises(FixtureLookupError, req.getfuncargvalue, "notexists")
462-
val = req.getfuncargvalue("something")
461+
pytest.raises(FixtureLookupError, req.getfixturevalue, "notexists")
462+
val = req.getfixturevalue("something")
463463
assert val == 1
464-
val = req.getfuncargvalue("something")
464+
val = req.getfixturevalue("something")
465465
assert val == 1
466-
val2 = req.getfuncargvalue("other")
466+
val2 = req.getfixturevalue("other")
467467
assert val2 == 2
468-
val2 = req.getfuncargvalue("other") # see about caching
468+
val2 = req.getfixturevalue("other") # see about caching
469469
assert val2 == 2
470470
pytest._fillfuncargs(item)
471471
assert item.funcargs["something"] == 1
@@ -801,7 +801,7 @@ def test_two_different_setups(arg1, arg2):
801801
def test_request_cached_setup_getfuncargvalue(self, testdir):
802802
testdir.makepyfile("""
803803
def pytest_funcarg__arg1(request):
804-
arg1 = request.getfuncargvalue("arg2")
804+
arg1 = request.getfixturevalue("arg2")
805805
return request.cached_setup(lambda: arg1 + 1)
806806
def pytest_funcarg__arg2(request):
807807
return request.cached_setup(lambda: 10)
@@ -1104,7 +1104,7 @@ def test_2(arg2):
11041104

11051105
class TestFixtureManagerParseFactories:
11061106
def pytest_funcarg__testdir(self, request):
1107-
testdir = request.getfuncargvalue("testdir")
1107+
testdir = request.getfixturevalue("testdir")
11081108
testdir.makeconftest("""
11091109
def pytest_funcarg__hello(request):
11101110
return "conftest"
@@ -1790,9 +1790,9 @@ def test_4(arg, created, finalized):
17901790
reprec.assertoutcome(passed=4)
17911791

17921792
@pytest.mark.parametrize("method", [
1793-
'request.getfuncargvalue("arg")',
1793+
'request.getfixturevalue("arg")',
17941794
'request.cached_setup(lambda: None, scope="function")',
1795-
], ids=["getfuncargvalue", "cached_setup"])
1795+
], ids=["getfixturevalue", "cached_setup"])
17961796
def test_scope_mismatch_various(self, testdir, method):
17971797
testdir.makeconftest("""
17981798
import pytest

testing/python/metafunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def pytest_generate_tests(metafunc):
727727
metafunc.parametrize("arg2", [10], indirect=True)
728728
729729
def pytest_funcarg__arg1(request):
730-
x = request.getfuncargvalue("arg2")
730+
x = request.getfixturevalue("arg2")
731731
return x + request.param
732732
733733
def pytest_funcarg__arg2(request):

testing/test_genscript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def standalone(request):
88

99
class Standalone:
1010
def __init__(self, request):
11-
self.testdir = request.getfuncargvalue("testdir")
11+
self.testdir = request.getfixturevalue("testdir")
1212
script = "mypytest"
1313
result = self.testdir.runpytest("--genscript=%s" % script)
1414
assert result.ret == 0

testing/test_pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def runpdb_and_get_report(testdir, source):
1313

1414
class TestPDB:
1515
def pytest_funcarg__pdblist(self, request):
16-
monkeypatch = request.getfuncargvalue("monkeypatch")
16+
monkeypatch = request.getfixturevalue("monkeypatch")
1717
pdblist = []
1818
def mypdb(*args):
1919
pdblist.append(args)

0 commit comments

Comments
 (0)