Skip to content

Commit

Permalink
Merge 0c74f4b into 5d8d1db
Browse files Browse the repository at this point in the history
  • Loading branch information
tomviner committed Jun 21, 2016
2 parents 5d8d1db + 0c74f4b commit 0909c22
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -17,11 +17,16 @@
is specified on the command line together with the ``--pyargs``
option. Thanks to `@taschini`_ for the PR (`#1597`_).

* Rename ``getfuncargvalue`` to ``getfixturevalue``. `getfuncargvalue`
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
for PR (`#1626`_).

*

.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
Expand Down
2 changes: 1 addition & 1 deletion _pytest/doctest.py
Expand Up @@ -70,7 +70,7 @@ def __init__(self, name, parent, runner=None, dtest=None):
def setup(self):
if self.dtest is not None:
self.fixture_request = _setup_fixtures(self)
globs = dict(getfixture=self.fixture_request.getfuncargvalue)
globs = dict(getfixture=self.fixture_request.getfixturevalue)
self.dtest.globs.update(globs)

def runtest(self):
Expand Down
22 changes: 12 additions & 10 deletions _pytest/python.py
Expand Up @@ -1469,7 +1469,7 @@ def _getnextfixturedef(self, argname):
fixturedefs = self._arg2fixturedefs.get(argname, None)
if fixturedefs is None:
# we arrive here because of a a dynamic call to
# getfuncargvalue(argname) usage which was naturally
# getfixturevalue(argname) usage which was naturally
# not known at parsing/collection time
fixturedefs = self._fixturemanager.getfixturedefs(
argname, self._pyfuncitem.parent.nodeid)
Expand Down Expand Up @@ -1564,7 +1564,7 @@ def _fillfixtures(self):
fixturenames = getattr(item, "fixturenames", self.fixturenames)
for argname in fixturenames:
if argname not in item.funcargs:
item.funcargs[argname] = self.getfuncargvalue(argname)
item.funcargs[argname] = self.getfixturevalue(argname)

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

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

# now deprecated
getfuncargvalue = getfixturevalue

def _get_active_fixturedef(self, argname):
try:
return self._fixturedefs[argname]
Expand All @@ -1624,7 +1626,7 @@ class PseudoFixtureDef:
raise
# remove indent to prevent the python3 exception
# from leaking into the call
result = self._getfuncargvalue(fixturedef)
result = self._getfixturevalue(fixturedef)
self._funcargs[argname] = result
self._fixturedefs[argname] = fixturedef
return fixturedef
Expand All @@ -1640,7 +1642,7 @@ def _get_fixturestack(self):
l.append(fixturedef)
current = current._parent_request

def _getfuncargvalue(self, fixturedef):
def _getfixturevalue(self, fixturedef):
# prepare a subrequest object before calling fixture function
# (latter managed by fixturedef)
argname = fixturedef.argname
Expand Down
2 changes: 1 addition & 1 deletion doc/en/genapi.py
Expand Up @@ -32,7 +32,7 @@ def docmethod(self, method):

def pytest_funcarg__a(request):
with Writer("request") as writer:
writer.docmethod(request.getfuncargvalue)
writer.docmethod(request.getfixturevalue)
writer.docmethod(request.cached_setup)
writer.docmethod(request.addfinalizer)
writer.docmethod(request.applymarker)
Expand Down
2 changes: 1 addition & 1 deletion testing/code/test_excinfo.py
Expand Up @@ -327,7 +327,7 @@ class TestFormattedExcinfo:
def pytest_funcarg__importasmod(self, request):
def importasmod(source):
source = _pytest._code.Source(source)
tmpdir = request.getfuncargvalue("tmpdir")
tmpdir = request.getfixturevalue("tmpdir")
modpath = tmpdir.join("mod.py")
tmpdir.ensure("__init__.py")
modpath.write(source)
Expand Down
24 changes: 12 additions & 12 deletions testing/python/fixture.py
Expand Up @@ -93,12 +93,12 @@ def test_conftest_funcargs_only_available_in_subdir(self, testdir):
sub1.join("conftest.py").write(_pytest._code.Source("""
import pytest
def pytest_funcarg__arg1(request):
pytest.raises(Exception, "request.getfuncargvalue('arg2')")
pytest.raises(Exception, "request.getfixturevalue('arg2')")
"""))
sub2.join("conftest.py").write(_pytest._code.Source("""
import pytest
def pytest_funcarg__arg2(request):
pytest.raises(Exception, "request.getfuncargvalue('arg1')")
pytest.raises(Exception, "request.getfixturevalue('arg1')")
"""))

sub1.join("test_in_sub1.py").write("def test_1(arg1): pass")
Expand Down Expand Up @@ -442,7 +442,7 @@ def pytest_funcarg__something(request):
""")
testdir.makepyfile("""
def pytest_funcarg__something(request):
return request.getfuncargvalue("something") + 1
return request.getfixturevalue("something") + 1
def test_func(something):
assert something == 2
""")
Expand All @@ -458,14 +458,14 @@ def pytest_funcarg__other(request):
def test_func(something): pass
""")
req = item._request
pytest.raises(FixtureLookupError, req.getfuncargvalue, "notexists")
val = req.getfuncargvalue("something")
pytest.raises(FixtureLookupError, req.getfixturevalue, "notexists")
val = req.getfixturevalue("something")
assert val == 1
val = req.getfuncargvalue("something")
val = req.getfixturevalue("something")
assert val == 1
val2 = req.getfuncargvalue("other")
val2 = req.getfixturevalue("other")
assert val2 == 2
val2 = req.getfuncargvalue("other") # see about caching
val2 = req.getfixturevalue("other") # see about caching
assert val2 == 2
pytest._fillfuncargs(item)
assert item.funcargs["something"] == 1
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_two_different_setups(arg1, arg2):
def test_request_cached_setup_getfuncargvalue(self, testdir):
testdir.makepyfile("""
def pytest_funcarg__arg1(request):
arg1 = request.getfuncargvalue("arg2")
arg1 = request.getfixturevalue("arg2")
return request.cached_setup(lambda: arg1 + 1)
def pytest_funcarg__arg2(request):
return request.cached_setup(lambda: 10)
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def test_2(arg2):

class TestFixtureManagerParseFactories:
def pytest_funcarg__testdir(self, request):
testdir = request.getfuncargvalue("testdir")
testdir = request.getfixturevalue("testdir")
testdir.makeconftest("""
def pytest_funcarg__hello(request):
return "conftest"
Expand Down Expand Up @@ -1790,9 +1790,9 @@ def test_4(arg, created, finalized):
reprec.assertoutcome(passed=4)

@pytest.mark.parametrize("method", [
'request.getfuncargvalue("arg")',
'request.getfixturevalue("arg")',
'request.cached_setup(lambda: None, scope="function")',
], ids=["getfuncargvalue", "cached_setup"])
], ids=["getfixturevalue", "cached_setup"])
def test_scope_mismatch_various(self, testdir, method):
testdir.makeconftest("""
import pytest
Expand Down
2 changes: 1 addition & 1 deletion testing/python/metafunc.py
Expand Up @@ -727,7 +727,7 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize("arg2", [10], indirect=True)
def pytest_funcarg__arg1(request):
x = request.getfuncargvalue("arg2")
x = request.getfixturevalue("arg2")
return x + request.param
def pytest_funcarg__arg2(request):
Expand Down
2 changes: 1 addition & 1 deletion testing/test_genscript.py
Expand Up @@ -8,7 +8,7 @@ def standalone(request):

class Standalone:
def __init__(self, request):
self.testdir = request.getfuncargvalue("testdir")
self.testdir = request.getfixturevalue("testdir")
script = "mypytest"
result = self.testdir.runpytest("--genscript=%s" % script)
assert result.ret == 0
Expand Down
2 changes: 1 addition & 1 deletion testing/test_pdb.py
Expand Up @@ -13,7 +13,7 @@ def runpdb_and_get_report(testdir, source):

class TestPDB:
def pytest_funcarg__pdblist(self, request):
monkeypatch = request.getfuncargvalue("monkeypatch")
monkeypatch = request.getfixturevalue("monkeypatch")
pdblist = []
def mypdb(*args):
pdblist.append(args)
Expand Down

0 comments on commit 0909c22

Please sign in to comment.