Move UnformattedWarning to _pytest.warning_types
This commit is contained in:
parent
da6830f19b
commit
ae8f3695b5
|
@ -10,24 +10,8 @@ in case of warnings which need to format their messages.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import attr
|
|
||||||
|
|
||||||
from _pytest.warning_types import RemovedInPytest4Warning
|
from _pytest.warning_types import UnformattedWarning, RemovedInPytest4Warning
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
|
||||||
class UnformattedWarning(object):
|
|
||||||
"""Used to hold warnings that need to format their message at runtime, as opposed to a direct message.
|
|
||||||
|
|
||||||
Using this class avoids to keep all the warning types and messages in this module, avoiding misuse.
|
|
||||||
"""
|
|
||||||
|
|
||||||
category = attr.ib()
|
|
||||||
template = attr.ib()
|
|
||||||
|
|
||||||
def format(self, **kwargs):
|
|
||||||
"""Returns an instance of the warning category, formatted with given kwargs"""
|
|
||||||
return self.category(self.template.format(**kwargs))
|
|
||||||
|
|
||||||
|
|
||||||
MAIN_STR_ARGS = RemovedInPytest4Warning(
|
MAIN_STR_ARGS = RemovedInPytest4Warning(
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import attr
|
||||||
|
|
||||||
|
|
||||||
class PytestWarning(UserWarning):
|
class PytestWarning(UserWarning):
|
||||||
"""
|
"""
|
||||||
Bases: :class:`UserWarning`.
|
Bases: :class:`UserWarning`.
|
||||||
|
@ -39,4 +42,19 @@ class PytestExperimentalApiWarning(PytestWarning, FutureWarning):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class UnformattedWarning(object):
|
||||||
|
"""Used to hold warnings that need to format their message at runtime, as opposed to a direct message.
|
||||||
|
|
||||||
|
Using this class avoids to keep all the warning types and messages in this module, avoiding misuse.
|
||||||
|
"""
|
||||||
|
|
||||||
|
category = attr.ib()
|
||||||
|
template = attr.ib()
|
||||||
|
|
||||||
|
def format(self, **kwargs):
|
||||||
|
"""Returns an instance of the warning category, formatted with given kwargs"""
|
||||||
|
return self.category(self.template.format(**kwargs))
|
||||||
|
|
||||||
|
|
||||||
PYTESTER_COPY_EXAMPLE = PytestExperimentalApiWarning.simple("testdir.copy_example")
|
PYTESTER_COPY_EXAMPLE = PytestExperimentalApiWarning.simple("testdir.copy_example")
|
||||||
|
|
Loading…
Reference in New Issue