From 8ce3aeadbfc4c88c785ff2d86c644a1e5ea4d1b1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 4 Sep 2018 10:48:11 -0300 Subject: [PATCH] Move PytestExerimentalApiWarning to warning_types --- doc/en/warnings.rst | 2 ++ src/_pytest/experiments.py | 13 ------------- src/_pytest/pytester.py | 6 ++++-- src/_pytest/warning_types.py | 17 +++++++++++++++++ src/pytest.py | 4 +++- tox.ini | 4 ++-- 6 files changed, 28 insertions(+), 18 deletions(-) delete mode 100644 src/_pytest/experiments.py diff --git a/doc/en/warnings.rst b/doc/en/warnings.rst index eac997308..6db100fd7 100644 --- a/doc/en/warnings.rst +++ b/doc/en/warnings.rst @@ -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 + diff --git a/src/_pytest/experiments.py b/src/_pytest/experiments.py deleted file mode 100644 index aa6b66446..000000000 --- a/src/_pytest/experiments.py +++ /dev/null @@ -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") diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 002eb62a5..ea0ccf136 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -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") diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 092a5a430..407cfb100 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -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 + ) + ) diff --git a/src/pytest.py b/src/pytest.py index c5a066662..e29e6116e 100644 --- a/src/pytest.py +++ b/src/pytest.py @@ -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", diff --git a/tox.ini b/tox.ini index 4b5eae066..a071b5bf4 100644 --- a/tox.ini +++ b/tox.ini @@ -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