Make 'request' a reserved name for fixtures
This commit is contained in:
@@ -50,11 +50,11 @@ def iscoroutinefunction(func):
|
||||
)
|
||||
|
||||
|
||||
def getlocation(function, curdir):
|
||||
def getlocation(function, curdir=None):
|
||||
function = get_real_func(function)
|
||||
fn = py.path.local(inspect.getfile(function))
|
||||
lineno = function.__code__.co_firstlineno
|
||||
if fn.relto(curdir):
|
||||
if curdir is not None and fn.relto(curdir):
|
||||
fn = fn.relto(curdir)
|
||||
return "%s:%d" % (fn, lineno + 1)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ from pluggy import PluginManager
|
||||
|
||||
import _pytest._code
|
||||
import _pytest.assertion
|
||||
import _pytest.deprecated
|
||||
import _pytest.hookspec # the extension point definitions
|
||||
from .exceptions import PrintHelp
|
||||
from .exceptions import UsageError
|
||||
|
||||
@@ -19,11 +19,6 @@ DEPRECATED_EXTERNAL_PLUGINS = {
|
||||
}
|
||||
|
||||
|
||||
FIXTURE_NAMED_REQUEST = PytestDeprecationWarning(
|
||||
"'request' is a reserved name for fixtures and will raise an error in future versions"
|
||||
)
|
||||
|
||||
|
||||
FUNCARGNAMES = PytestDeprecationWarning(
|
||||
"The `funcargnames` attribute was an alias for `fixturenames`, "
|
||||
"since pytest 2.3 - use the newer attribute instead."
|
||||
|
||||
@@ -2,7 +2,6 @@ import functools
|
||||
import inspect
|
||||
import itertools
|
||||
import sys
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from collections import deque
|
||||
from collections import OrderedDict
|
||||
@@ -26,7 +25,6 @@ from _pytest.compat import getlocation
|
||||
from _pytest.compat import is_generator
|
||||
from _pytest.compat import NOTSET
|
||||
from _pytest.compat import safe_getattr
|
||||
from _pytest.deprecated import FIXTURE_NAMED_REQUEST
|
||||
from _pytest.outcomes import fail
|
||||
from _pytest.outcomes import TEST_OUTCOME
|
||||
|
||||
@@ -971,7 +969,13 @@ class FixtureFunctionMarker:
|
||||
|
||||
name = self.name or function.__name__
|
||||
if name == "request":
|
||||
warnings.warn(FIXTURE_NAMED_REQUEST)
|
||||
location = getlocation(function)
|
||||
fail(
|
||||
"'request' is a reserved word for fixtures, use another name:\n {}".format(
|
||||
location
|
||||
),
|
||||
pytrace=False,
|
||||
)
|
||||
function._pytestfixturefunction = self
|
||||
return function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user