Show a better message when 'request' is used in parametrize (#6184)

Show a better message when 'request' is used in parametrize
This commit is contained in:
Bruno Oliveira 2019-11-13 20:36:23 -03:00 committed by GitHub
commit 92d6a0500b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,2 @@
Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
user-friendly error.

View File

@ -977,6 +977,12 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
)
del argvalues
if "request" in argnames:
fail(
"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
pytrace=False,
)
if scope is None:
scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect)

View File

@ -72,6 +72,19 @@ class TestMetafunc:
):
metafunc.parametrize("x", [1], scope="doggy")
def test_parametrize_request_name(self, testdir):
"""Show proper error when 'request' is used as a parameter name in parametrize (#6183)"""
def func(request):
raise NotImplementedError()
metafunc = self.Metafunc(func)
with pytest.raises(
pytest.fail.Exception,
match=r"'request' is a reserved name and cannot be used in @pytest.mark.parametrize",
):
metafunc.parametrize("request", [1])
def test_find_parametrized_scope(self):
"""unittest for _find_parametrized_scope (#3941)"""
from _pytest.python import _find_parametrized_scope