-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeprecate_function_test.py
More file actions
36 lines (26 loc) · 962 Bytes
/
Copy pathdeprecate_function_test.py
File metadata and controls
36 lines (26 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
The following example shows how to deprecate a function properly.
It shows as well, how to test such deprecation.
Supported IDE's:
Name Version Supported
-----------------------------------------
Atom 3.40.0 No
PyCharm 2019.3 Yes
Sublime Text 3.2.2 No
"""
from warnings import catch_warnings, warn
def a_deprecated_function():
"""
A function which throws a DeprecationWarning with a particular reason.
"""
warn('This method is deprecated', DeprecationWarning, stacklevel=2)
def test_a_deprecated_function():
with catch_warnings(record=True) as w:
a_deprecated_function()
assert len(w) == 1
w0 = w[0]
assert str(w0.message) == 'This method is deprecated'
assert issubclass(w0.category, DeprecationWarning)
assert w0.filename == __file__
if __name__ == '__main__':
a_deprecated_function()