Use explicit instances when calling warnings.warn_explicit

This commit is contained in:
Bruno Oliveira 2018-09-04 16:29:48 -03:00
parent 3db76ccf3d
commit d3ca739c00
6 changed files with 19 additions and 14 deletions

View File

@ -755,8 +755,8 @@ class AssertionRewriter(ast.NodeVisitor):
import warnings import warnings
warnings.warn_explicit( warnings.warn_explicit(
"assertion is always true, perhaps remove parentheses?", PytestWarning("assertion is always true, perhaps remove parentheses?"),
PytestWarning, category=None,
filename=str(self.module_path), filename=str(self.module_path),
lineno=assert_.lineno, lineno=assert_.lineno,
) )

View File

@ -419,11 +419,9 @@ class PytestPluginManager(PluginManager):
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST
) )
from _pytest.warning_types import RemovedInPytest4Warning
warnings.warn_explicit( warnings.warn_explicit(
PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST, PYTEST_PLUGINS_FROM_NON_TOP_LEVEL_CONFTEST,
RemovedInPytest4Warning, category=None,
filename=str(conftestpath), filename=str(conftestpath),
lineno=0, lineno=0,
) )
@ -629,7 +627,10 @@ class Config(object):
if nodeid: if nodeid:
msg = "{}: {}".format(nodeid, msg) msg = "{}: {}".format(nodeid, msg)
warnings.warn_explicit( warnings.warn_explicit(
msg, RemovedInPytest4Warning, filename=filename, lineno=lineno RemovedInPytest4Warning(msg),
category=None,
filename=filename,
lineno=lineno,
) )
self.hook.pytest_logwarning.call_historic( self.hook.pytest_logwarning.call_historic(
kwargs=dict( kwargs=dict(

View File

@ -72,7 +72,7 @@ METAFUNC_ADD_CALL = RemovedInPytest4Warning(
"Please use Metafunc.parametrize instead." "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, " "Defining pytest_plugins in a non-top-level conftest is deprecated, "
"because it affects the entire directory tree in a non-explicit way.\n" "because it affects the entire directory tree in a non-explicit way.\n"
"Please move it to the top level conftest file instead." "Please move it to the top level conftest file instead."

View File

@ -1284,8 +1284,10 @@ class FixtureManager(object):
filename, lineno = getfslineno(obj) filename, lineno = getfslineno(obj)
warnings.warn_explicit( warnings.warn_explicit(
deprecated.FUNCARG_PREFIX.format(name=name), RemovedInPytest4Warning(
RemovedInPytest4Warning, deprecated.FUNCARG_PREFIX.format(name=name)
),
category=None,
filename=str(filename), filename=str(filename),
lineno=lineno + 1, lineno=lineno + 1,
) )

View File

@ -241,8 +241,10 @@ def pytest_pycollect_makeitem(collector, name, obj):
if not (isfunction(obj) or isfunction(get_real_func(obj))): if not (isfunction(obj) or isfunction(get_real_func(obj))):
filename, lineno = getfslineno(obj) filename, lineno = getfslineno(obj)
warnings.warn_explicit( warnings.warn_explicit(
message="cannot collect %r because it is not a function." % name, message=PytestWarning(
category=PytestWarning, "cannot collect %r because it is not a function." % name
),
category=None,
filename=str(filename), filename=str(filename),
lineno=lineno + 1, lineno=lineno + 1,
) )

View File

@ -202,7 +202,7 @@ def test_pytest_plugins_in_non_top_level_conftest_deprecated(testdir):
) )
res = testdir.runpytest_subprocess() res = testdir.runpytest_subprocess()
assert res.ret == 0 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( res.stdout.fnmatch_lines(
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format( "*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
sep=os.sep, msg=msg 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() res = testdir.runpytest_subprocess()
assert res.ret == 0 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( res.stdout.fnmatch_lines(
"*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format( "*subdirectory{sep}conftest.py:0: RemovedInPytest4Warning: {msg}*".format(
sep=os.sep, msg=msg 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() res = testdir.runpytest_subprocess()
assert res.ret == 0 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() assert msg not in res.stdout.str()