Skip to content

Commit 3d263c6

Browse files
authored
Merge pull request #1626 from tomviner/issue1625/rename-getfuncargvalue
issue1625, rename getfuncargvalue to getfixturevalue
2 parents 6359e75 + df9918e commit 3d263c6

File tree

9 files changed

+56
-36
lines changed

9 files changed

+56
-36
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@
2727
Thanks `@Vogtinator`_ for reporting. Thanks to `@RedBeardCode`_ and
2828
`@tomviner`_ for PR.
2929

30+
* Rename ``getfuncargvalue`` to ``getfixturevalue``. ``getfuncargvalue`` is
31+
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
32+
for PR (`#1626`_).
33+
3034
*
3135

3236
.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
3337
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
3438
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
3539
.. _#460: https://github.com/pytest-dev/pytest/pull/460
3640
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
41+
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
3742

3843
.. _@graingert: https://github.com/graingert
3944
.. _@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: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import types
77
import sys
8+
import warnings
89

910
import py
1011
import pytest
@@ -1469,7 +1470,7 @@ def _getnextfixturedef(self, argname):
14691470
fixturedefs = self._arg2fixturedefs.get(argname, None)
14701471
if fixturedefs is None:
14711472
# we arrive here because of a a dynamic call to
1472-
# getfuncargvalue(argname) usage which was naturally
1473+
# getfixturevalue(argname) usage which was naturally
14731474
# not known at parsing/collection time
14741475
fixturedefs = self._fixturemanager.getfixturedefs(
14751476
argname, self._pyfuncitem.parent.nodeid)
@@ -1564,7 +1565,7 @@ def _fillfixtures(self):
15641565
fixturenames = getattr(item, "fixturenames", self.fixturenames)
15651566
for argname in fixturenames:
15661567
if argname not in item.funcargs:
1567-
item.funcargs[argname] = self.getfuncargvalue(argname)
1568+
item.funcargs[argname] = self.getfixturevalue(argname)
15681569

15691570
def cached_setup(self, setup, teardown=None, scope="module", extrakey=None):
15701571
""" (deprecated) Return a testing resource managed by ``setup`` &
@@ -1598,17 +1599,23 @@ def finalizer():
15981599
self._addfinalizer(finalizer, scope=scope)
15991600
return val
16001601

1601-
def getfuncargvalue(self, argname):
1602-
""" Dynamically retrieve a named fixture function argument.
1602+
def getfixturevalue(self, argname):
1603+
""" Dynamically run a named fixture function.
16031604
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
1605+
Declaring fixtures via function argument is recommended where possible.
1606+
But if you can only decide whether to use another fixture at test
16071607
setup time, you may use this function to retrieve it inside a fixture
1608-
function body.
1608+
or test function body.
16091609
"""
16101610
return self._get_active_fixturedef(argname).cached_result[0]
16111611

1612+
def getfuncargvalue(self, argname):
1613+
""" Deprecated, use getfixturevalue. """
1614+
warnings.warn(
1615+
"use of getfuncargvalue is deprecated, use getfixturevalue",
1616+
DeprecationWarning)
1617+
return self.getfixturevalue(argname)
1618+
16121619
def _get_active_fixturedef(self, argname):
16131620
try:
16141621
return self._fixturedefs[argname]
@@ -1624,7 +1631,7 @@ class PseudoFixtureDef:
16241631
raise
16251632
# remove indent to prevent the python3 exception
16261633
# from leaking into the call
1627-
result = self._getfuncargvalue(fixturedef)
1634+
result = self._getfixturevalue(fixturedef)
16281635
self._funcargs[argname] = result
16291636
self._fixturedefs[argname] = fixturedef
16301637
return fixturedef
@@ -1640,7 +1647,7 @@ def _get_fixturestack(self):
16401647
l.append(fixturedef)
16411648
current = current._parent_request
16421649

1643-
def _getfuncargvalue(self, fixturedef):
1650+
def _getfixturevalue(self, fixturedef):
16441651
# prepare a subrequest object before calling fixture function
16451652
# (latter managed by fixturedef)
16461653
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: 27 additions & 19 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")
@@ -435,21 +435,23 @@ def test_method(self, something):
435435
assert len(arg2fixturedefs) == 1
436436
assert arg2fixturedefs[0].__name__ == "pytest_funcarg__something"
437437

438-
def test_getfuncargvalue_recursive(self, testdir):
438+
def test_getfixturevalue_recursive(self, testdir):
439439
testdir.makeconftest("""
440440
def pytest_funcarg__something(request):
441441
return 1
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
""")
449449
reprec = testdir.inline_run()
450450
reprec.assertoutcome(passed=1)
451451

452-
def test_getfuncargvalue(self, testdir):
452+
@pytest.mark.parametrize(
453+
'getfixmethod', ('getfixturevalue', 'getfuncargvalue'))
454+
def test_getfixturevalue(self, testdir, getfixmethod):
453455
item = testdir.getitem("""
454456
l = [2]
455457
def pytest_funcarg__something(request): return 1
@@ -458,14 +460,15 @@ def pytest_funcarg__other(request):
458460
def test_func(something): pass
459461
""")
460462
req = item._request
461-
pytest.raises(FixtureLookupError, req.getfuncargvalue, "notexists")
462-
val = req.getfuncargvalue("something")
463+
fixture_fetcher = getattr(req, getfixmethod)
464+
pytest.raises(FixtureLookupError, fixture_fetcher, "notexists")
465+
val = fixture_fetcher("something")
463466
assert val == 1
464-
val = req.getfuncargvalue("something")
467+
val = fixture_fetcher("something")
465468
assert val == 1
466-
val2 = req.getfuncargvalue("other")
469+
val2 = fixture_fetcher("other")
467470
assert val2 == 2
468-
val2 = req.getfuncargvalue("other") # see about caching
471+
val2 = fixture_fetcher("other") # see about caching
469472
assert val2 == 2
470473
pytest._fillfuncargs(item)
471474
assert item.funcargs["something"] == 1
@@ -812,10 +815,10 @@ def test_two_different_setups(arg1, arg2):
812815
"*1 passed*"
813816
])
814817

815-
def test_request_cached_setup_getfuncargvalue(self, testdir):
818+
def test_request_cached_setup_getfixturevalue(self, testdir):
816819
testdir.makepyfile("""
817820
def pytest_funcarg__arg1(request):
818-
arg1 = request.getfuncargvalue("arg2")
821+
arg1 = request.getfixturevalue("arg2")
819822
return request.cached_setup(lambda: arg1 + 1)
820823
def pytest_funcarg__arg2(request):
821824
return request.cached_setup(lambda: 10)
@@ -1118,7 +1121,7 @@ def test_2(arg2):
11181121

11191122
class TestFixtureManagerParseFactories:
11201123
def pytest_funcarg__testdir(self, request):
1121-
testdir = request.getfuncargvalue("testdir")
1124+
testdir = request.getfixturevalue("testdir")
11221125
testdir.makeconftest("""
11231126
def pytest_funcarg__hello(request):
11241127
return "conftest"
@@ -1804,9 +1807,9 @@ def test_4(arg, created, finalized):
18041807
reprec.assertoutcome(passed=4)
18051808

18061809
@pytest.mark.parametrize("method", [
1807-
'request.getfuncargvalue("arg")',
1810+
'request.getfixturevalue("arg")',
18081811
'request.cached_setup(lambda: None, scope="function")',
1809-
], ids=["getfuncargvalue", "cached_setup"])
1812+
], ids=["getfixturevalue", "cached_setup"])
18101813
def test_scope_mismatch_various(self, testdir, method):
18111814
testdir.makeconftest("""
18121815
import pytest
@@ -2737,6 +2740,7 @@ def test_1(arg1):
27372740
*def arg1*
27382741
""")
27392742

2743+
27402744
class TestParameterizedSubRequest:
27412745
def test_call_from_fixture(self, testdir):
27422746
testfile = testdir.makepyfile("""
@@ -2748,7 +2752,7 @@ def fix_with_param(request):
27482752
27492753
@pytest.fixture
27502754
def get_named_fixture(request):
2751-
return request.getfuncargvalue('fix_with_param')
2755+
return request.getfixturevalue('fix_with_param')
27522756
27532757
def test_foo(request, get_named_fixture):
27542758
pass
@@ -2773,7 +2777,7 @@ def fix_with_param(request):
27732777
return request.param
27742778
27752779
def test_foo(request):
2776-
request.getfuncargvalue('fix_with_param')
2780+
request.getfixturevalue('fix_with_param')
27772781
""")
27782782
result = testdir.runpytest()
27792783
result.stdout.fnmatch_lines("""
@@ -2797,7 +2801,7 @@ def fix_with_param(request):
27972801

27982802
testfile = testdir.makepyfile("""
27992803
def test_foo(request):
2800-
request.getfuncargvalue('fix_with_param')
2804+
request.getfixturevalue('fix_with_param')
28012805
""")
28022806
result = testdir.runpytest()
28032807
result.stdout.fnmatch_lines("""
@@ -2827,7 +2831,7 @@ def fix_with_param(request):
28272831
from fix import fix_with_param
28282832
28292833
def test_foo(request):
2830-
request.getfuncargvalue('fix_with_param')
2834+
request.getfixturevalue('fix_with_param')
28312835
"""))
28322836

28332837
tests_dir.chdir()
@@ -2842,3 +2846,7 @@ def test_foo(request):
28422846
E*{1}:5
28432847
*1 failed*
28442848
""".format(fixfile.strpath, testfile.basename))
2849+
2850+
2851+
def test_getfuncargvalue_is_deprecated(request):
2852+
pytest.deprecated_call(request.getfuncargvalue, 'tmpdir')

testing/python/metafunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,14 @@ def test_hello(arg1, arg2):
720720
"*4 failed*",
721721
])
722722

723-
def test_parametrize_and_inner_getfuncargvalue(self, testdir):
723+
def test_parametrize_and_inner_getfixturevalue(self, testdir):
724724
p = testdir.makepyfile("""
725725
def pytest_generate_tests(metafunc):
726726
metafunc.parametrize("arg1", [1], indirect=True)
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)