Skip to content

Commit

Permalink
Show a better message when 'request' is used in parametrize
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Nov 13, 2019
1 parent 55a58bc commit 0094272
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog/6183.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
user-friendly error.
8 changes: 8 additions & 0 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,14 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None, scope=None)
)
del argvalues

if "request" in argnames:
# from _pytest.config import UsageError
# raise UsageError('foo')
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)

Expand Down
13 changes: 13 additions & 0 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ def func(x):
):
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):
pass

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
Expand Down

0 comments on commit 0094272

Please sign in to comment.