Move PytestExerimentalApiWarning to warning_types

This commit is contained in:
Bruno Oliveira 2018-09-04 10:48:11 -03:00
parent b818314045
commit 8ce3aeadbf
6 changed files with 28 additions and 18 deletions

View File

@ -378,3 +378,5 @@ The following warning types ares used by pytest and are part of the public API:
.. autoclass:: pytest.RemovedInPytest4Warning
.. autoclass:: pytest.PytestExerimentalApiWarning

View File

@ -1,13 +0,0 @@
class PytestExerimentalApiWarning(FutureWarning):
"warning category used to denote experiments in pytest"
@classmethod
def simple(cls, apiname):
return cls(
"{apiname} is an experimental api that may change over time".format(
apiname=apiname
)
)
PYTESTER_COPY_EXAMPLE = PytestExerimentalApiWarning.simple("testdir.copy_example")

View File

@ -642,10 +642,12 @@ class Testdir(object):
return p
def copy_example(self, name=None):
from . import experiments
import warnings
warnings.warn(experiments.PYTESTER_COPY_EXAMPLE, stacklevel=2)
warnings.warn(
pytest.PytestExerimentalApiWarning.simple("testdir.copy_example"),
stacklevel=2,
)
example_dir = self.request.config.getini("pytester_example_dir")
if example_dir is None:
raise ValueError("pytester_example_dir is unset, can't copy examples")

View File

@ -20,3 +20,20 @@ class RemovedInPytest4Warning(PytestDeprecationWarning):
Warning class for features scheduled to be removed in pytest 4.0.
"""
class PytestExerimentalApiWarning(PytestWarning, FutureWarning):
"""
Bases: :class:`pytest.PytestWarning`, :class:`FutureWarning`.
Warning category used to denote experiments in pytest. Use sparingly as the API might change or even be
removed completely in future version
"""
@classmethod
def simple(cls, apiname):
return cls(
"{apiname} is an experimental api that may change over time".format(
apiname=apiname
)
)

View File

@ -24,6 +24,7 @@ from _pytest.warning_types import (
PytestWarning,
PytestDeprecationWarning,
RemovedInPytest4Warning,
PytestExerimentalApiWarning,
)
set_trace = __pytestPDB.set_trace
@ -53,8 +54,9 @@ __all__ = [
"Module",
"Package",
"param",
"PytestWarning",
"PytestDeprecationWarning",
"PytestExerimentalApiWarning",
"PytestWarning",
"raises",
"register_assert_rewrite",
"RemovedInPytest4Warning",

View File

@ -229,8 +229,8 @@ filterwarnings =
ignore:.*type argument to addoption.*:DeprecationWarning
# produced by python >=3.5 on execnet (pytest-xdist)
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
#pytests own futurewarnings
ignore::_pytest.experiments.PytestExerimentalApiWarning
# pytest's own futurewarnings
ignore::pytest.PytestExerimentalApiWarning
pytester_example_dir = testing/example_scripts
[flake8]
max-line-length = 120