Use explicit instances when calling warnings.warn_explicit
This commit is contained in:
parent
3db76ccf3d
commit
d3ca739c00
|
@ -755,8 +755,8 @@ class AssertionRewriter(ast.NodeVisitor):
|
|||
import warnings
|
||||
|
||||
warnings.warn_explicit(
|
||||
"assertion is always true, perhaps remove parentheses?",
|
||||
PytestWarning,
|
||||
PytestWarning("assertion is always true, perhaps remove parentheses?"),
|
||||
category=None,
|
||||
filename=str(self.module_path),
|
||||
lineno=assert_.lineno,
|
||||
)
|
||||
|
|
|
@ -419,11 +419,9 @@ class PytestPluginManager(PluginManager):
|
|||
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
|
||||
)
|
||||
|
||||
from _pytest.warning_types import RemovedInPytest4Warning
|
||||
|
||||
warnings.warn_explicit(
|
||||
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST,
|
||||
RemovedInPytest4Warning,
|
||||
category=None,
|
||||
filename=str(conftestpath),
|
||||
lineno=0,
|
||||
)
|
||||
|
@ -629,7 +627,10 @@ class Config(object):
|
|||
if nodeid:
|
||||
msg = "{}: {}".format(nodeid, msg)
|
||||
warnings.warn_explicit(
|
||||
msg, RemovedInPytest4Warning, filename=filename, lineno=lineno
|
||||
RemovedInPytest4Warning(msg),
|
||||
category=None,
|
||||
filename=filename,
|
||||
lineno=lineno,
|
||||
)
|
||||
self.hook.pytest_logwarning.call_historic(
|
||||
kwargs=dict(
|
||||
|
|
|
@ -72,7 +72,7 @@ METAFUNC_ADD_CALL = RemovedInPytest4Warning(
|
|||
"Please use Metafunc.parametrize instead."
|
||||
)
|
||||
|
||||
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = (
|
||||
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST = RemovedInPytest4Warning(
|
||||
"Defining pytest_plugins in a non-top-level conftest is deprecated, "
|
||||
"because it affects the entire directory tree in a non-explicit way.\n"
|
||||
"Please move it to the top level conftest file instead."
|
||||
|
|
|
@ -1284,8 +1284,10 @@ class FixtureManager(object):
|
|||
|
||||
filename, lineno = getfslineno(obj)
|
||||
warnings.warn_explicit(
|
||||
deprecated.FUNCARG_PREFIX.format(name=name),
|
||||
RemovedInPytest4Warning,
|
||||
RemovedInPytest4Warning(
|
||||
deprecated.FUNCARG_PREFIX.format(name=name)
|
||||
),
|
||||
category=None,
|
||||
filename=str(filename),
|
||||
lineno=lineno + 1,
|
||||
)
|
||||
|
|
|
@ -241,8 +241,10 @@ def pytest_pycollect_makeitem(collector, name, obj):
|
|||
if not (isfunction(obj) or isfunction(get_real_func(obj))):
|
||||
filename, lineno = getfslineno(obj)
|
||||
warnings.warn_explicit(
|
||||
message="cannot collect %r because it is not a function." % name,
|
||||
category=PytestWarning,
|
||||
message=PytestWarning(
|
||||
"cannot collect %r because it is not a function." % name
|
||||
),
|
||||
category=None,
|
||||
filename=str(filename),
|
||||
lineno=lineno + 1,
|
||||
)
|
||||
|
|
|
@ -202,7 +202,7 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
|
|||
)
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 0
|
||||
msg = PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST.splitlines()[0]
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
res.stdout.fnmatch_lines(
|
||||
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
|
||||
sep=os.sep, msg=msg
|
||||
|
@ -235,7 +235,7 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_top_level_confte
|
|||
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 0
|
||||
msg = PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST.splitlines()[0]
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
res.stdout.fnmatch_lines(
|
||||
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
|
||||
sep=os.sep, msg=msg
|
||||
|
@ -272,7 +272,7 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated_no_false_positives(
|
|||
)
|
||||
res = testdir.runpytest_subprocess()
|
||||
assert res.ret == 0
|
||||
msg = PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST.splitlines()[0]
|
||||
msg = str(PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST).splitlines()[0]
|
||||
assert msg not in res.stdout.str()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue