Skip to content

Commit ae8f369

Browse files
committed
Move UnformattedWarning to _pytest.warning_types
1 parent da6830f commit ae8f369

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/_pytest/deprecated.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,8 @@
1010
"""
1111
from __future__ import absolute_import, division, print_function
1212

13-
import attr
1413

15-
from _pytest.warning_types import RemovedInPytest4Warning
16-
17-
18-
@attr.s
19-
class UnformattedWarning(object):
20-
"""Used to hold warnings that need to format their message at runtime, as opposed to a direct message.
21-
22-
Using this class avoids to keep all the warning types and messages in this module, avoiding misuse.
23-
"""
24-
25-
category = attr.ib()
26-
template = attr.ib()
27-
28-
def format(self, **kwargs):
29-
"""Returns an instance of the warning category, formatted with given kwargs"""
30-
return self.category(self.template.format(**kwargs))
14+
from _pytest.warning_types import UnformattedWarning, RemovedInPytest4Warning
3115

3216

3317
MAIN_STR_ARGS = RemovedInPytest4Warning(

src/_pytest/warning_types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import attr
2+
3+
14
class PytestWarning(UserWarning):
25
"""
36
Bases: :class:`UserWarning`.
@@ -39,4 +42,19 @@ def simple(cls, apiname):
3942
)
4043

4144

45+
@attr.s
46+
class UnformattedWarning(object):
47+
"""Used to hold warnings that need to format their message at runtime, as opposed to a direct message.
48+
49+
Using this class avoids to keep all the warning types and messages in this module, avoiding misuse.
50+
"""
51+
52+
category = attr.ib()
53+
template = attr.ib()
54+
55+
def format(self, **kwargs):
56+
"""Returns an instance of the warning category, formatted with given kwargs"""
57+
return self.category(self.template.format(**kwargs))
58+
59+
4260
PYTESTER_COPY_EXAMPLE = PytestExperimentalApiWarning.simple("testdir.copy_example")

0 commit comments

Comments
 (0)