From 6f2c0fd2e8e8154c8129900c9a1c650068811404 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <nicoddemus@gmail.com>
Date: Wed, 13 Nov 2019 17:51:14 -0300
Subject: [PATCH] Show a better message when 'request' is used in parametrize

Fix #6183
---
 changelog/6183.bugfix.rst  |  2 ++
 src/_pytest/python.py      |  6 ++++++
 testing/python/metafunc.py | 13 +++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 changelog/6183.bugfix.rst

diff --git a/changelog/6183.bugfix.rst b/changelog/6183.bugfix.rst
new file mode 100644
index 000000000..5c4d66e24
--- /dev/null
+++ b/changelog/6183.bugfix.rst
@@ -0,0 +1,2 @@
+Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
+user-friendly error.
diff --git a/src/_pytest/python.py b/src/_pytest/python.py
index d16407bdd..306e5f217 100644
--- a/src/_pytest/python.py
+++ b/src/_pytest/python.py
@@ -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)
 
diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py
index 5becb0f8c..860b21ff2 100644
--- a/testing/python/metafunc.py
+++ b/testing/python/metafunc.py
@@ -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