diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 8c7944593..1f485eb89 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -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, ) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index dfee41bdf..993e091f2 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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( diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 5e2c58962..dea8bbde8 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -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." diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index cbfda9a82..068e6814c 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -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, ) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 10a3b1ec3..3ce70064e 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -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, ) diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index a74ce662d..fbaca4e30 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -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()