Make PytestWarning and RemovedInPytest4Warning part of the public API

This commit is contained in:
Bruno Oliveira 2018-09-03 13:14:57 -03:00
parent 78ac7d99f5
commit 19a01c9849
7 changed files with 40 additions and 47 deletions

View File

@ -176,9 +176,9 @@ def _prepareconfig(args=None, plugins=None):
else: else:
pluginmanager.register(plugin) pluginmanager.register(plugin)
if warning: if warning:
from _pytest.warning_types import PytestUsageWarning from _pytest.warning_types import PytestWarning
warnings.warn(warning, PytestUsageWarning) warnings.warn(warning, PytestWarning)
return pluginmanager.hook.pytest_cmdline_parse( return pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args pluginmanager=pluginmanager, args=args
) )

View File

@ -44,11 +44,7 @@ from _pytest.mark.structures import (
get_unpacked_marks, get_unpacked_marks,
normalize_mark_list, normalize_mark_list,
) )
from _pytest.warning_types import ( from _pytest.warning_types import RemovedInPytest4Warning, PytestWarning
PytestUsageWarning,
RemovedInPytest4Warning,
PytestWarning,
)
# relative paths that we use to filter traceback entries from appearing to the user; # relative paths that we use to filter traceback entries from appearing to the user;
# see filter_traceback # see filter_traceback
@ -671,12 +667,12 @@ class Class(PyCollector):
self.std_warn( self.std_warn(
"cannot collect test class %r because it has a " "cannot collect test class %r because it has a "
"__init__ constructor" % self.obj.__name__, "__init__ constructor" % self.obj.__name__,
PytestUsageWarning, PytestWarning,
) )
return [] return []
elif hasnew(self.obj): elif hasnew(self.obj):
self.std_warn( self.std_warn(
PytestUsageWarning( PytestWarning(
"cannot collect test class %r because it has a " "cannot collect test class %r because it has a "
"__new__ constructor" % self.obj.__name__ "__new__ constructor" % self.obj.__name__
) )

View File

@ -2,9 +2,5 @@ class PytestWarning(UserWarning):
"""Base class for all warnings emitted by pytest""" """Base class for all warnings emitted by pytest"""
class PytestUsageWarning(PytestWarning):
"""Warnings related to pytest usage: either command line or testing code."""
class RemovedInPytest4Warning(PytestWarning, DeprecationWarning): class RemovedInPytest4Warning(PytestWarning, DeprecationWarning):
"""warning class for features that will be removed in pytest 4.0""" """warning class for features that will be removed in pytest 4.0"""

View File

@ -19,45 +19,47 @@ from _pytest.main import Session
from _pytest.nodes import Item, Collector, File from _pytest.nodes import Item, Collector, File
from _pytest.fixtures import fillfixtures as _fillfuncargs from _pytest.fixtures import fillfixtures as _fillfuncargs
from _pytest.python import Package, Module, Class, Instance, Function, Generator from _pytest.python import Package, Module, Class, Instance, Function, Generator
from _pytest.python_api import approx, raises from _pytest.python_api import approx, raises
from _pytest.warning_types import PytestWarning, RemovedInPytest4Warning
set_trace = __pytestPDB.set_trace set_trace = __pytestPDB.set_trace
__all__ = [ __all__ = [
"main",
"UsageError",
"cmdline",
"hookspec",
"hookimpl",
"__version__", "__version__",
"register_assert_rewrite",
"freeze_includes",
"set_trace",
"warns",
"deprecated_call",
"fixture",
"yield_fixture",
"fail",
"skip",
"xfail",
"importorskip",
"exit",
"mark",
"param",
"approx",
"_fillfuncargs", "_fillfuncargs",
"Item", "approx",
"File",
"Collector",
"Package",
"Session",
"Module",
"Class", "Class",
"Instance", "cmdline",
"Collector",
"deprecated_call",
"exit",
"fail",
"File",
"fixture",
"freeze_includes",
"Function", "Function",
"Generator", "Generator",
"hookimpl",
"hookspec",
"importorskip",
"Instance",
"Item",
"main",
"mark",
"Module",
"Package",
"param",
"PytestWarning",
"raises", "raises",
"register_assert_rewrite",
"RemovedInPytest4Warning",
"Session",
"set_trace",
"skip",
"UsageError",
"warns",
"xfail",
"yield_fixture",
] ]
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -761,9 +761,8 @@ def test_rewritten():
def test_rewrite_warning(self, pytestconfig): def test_rewrite_warning(self, pytestconfig):
hook = AssertionRewritingHook(pytestconfig) hook = AssertionRewritingHook(pytestconfig)
from _pytest.warning_types import PytestWarning
with pytest.warns(PytestWarning): with pytest.warns(pytest.PytestWarning):
hook.mark_rewrite("_pytest") hook.mark_rewrite("_pytest")
def test_rewrite_module_imported_from_conftest(self, testdir): def test_rewrite_module_imported_from_conftest(self, testdir):

View File

@ -16,7 +16,7 @@ from _pytest.mark import (
from _pytest.nodes import Node from _pytest.nodes import Node
ignore_markinfo = pytest.mark.filterwarnings( ignore_markinfo = pytest.mark.filterwarnings(
"ignore:MarkInfo objects:_pytest.warning_types.RemovedInPytest4Warning" "ignore:MarkInfo objects:pytest.RemovedInPytest4Warning"
) )

View File

@ -218,9 +218,9 @@ norecursedirs = .tox ja .hg cx_freeze_source testing/example_scripts
xfail_strict=true xfail_strict=true
filterwarnings = filterwarnings =
error error
ignore:yield tests are deprecated, and scheduled to be removed in pytest 4.0: ignore:yield tests are deprecated, and scheduled to be removed in pytest 4.0:pytest.RemovedInPytest4Warning
ignore:Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0: ignore:Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0:pytest.RemovedInPytest4Warning
ignore:Module already imported so cannot be rewritten: ignore:Module already imported so cannot be rewritten:pytest.PytestWarning
# produced by path.local # produced by path.local
ignore:bad escape.*:DeprecationWarning:re ignore:bad escape.*:DeprecationWarning:re
# produced by path.readlines # produced by path.readlines