Skip to content

Commit

Permalink
Use FutureWarning instead of DeprecationWarning (#1188)
Browse files Browse the repository at this point in the history
* make Process.memory_info_ex() raise FutureWarning instead of DeprecationWarning because the latter is suppressed by default

* update HISTORY

* add test case
  • Loading branch information
giampaolo authored Dec 7, 2017
1 parent 82c77dc commit c3767da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
to print useful debug messages on stderr (useful in case of nasty errors).
- 1177_: added support for sensors_battery() on OSX. (patch by Arnon Yaari)
- 1183_: Process.children() is 2x faster on UNIX and 2.4x faster on Linux.
- 1188_: deprecated method Process.memory_info_ex() now warns by using
FutureWarning instead of DeprecationWarning.

**Bug fixes**

Expand Down
4 changes: 2 additions & 2 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,14 @@ def deprecated_method(replacement):
'replcement' is the method name which will be called instead.
"""
def outer(fun):
msg = "%s() is deprecated; use %s() instead" % (
msg = "%s() is deprecated and will be removed; use %s() instead" % (
fun.__name__, replacement)
if fun.__doc__ is None:
fun.__doc__ = msg

@functools.wraps(fun)
def inner(self, *args, **kwargs):
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
return getattr(self, replacement)(*args, **kwargs)
return inner
return outer
Expand Down
17 changes: 17 additions & 0 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import stat
import time
import traceback
import warnings
from contextlib import closing

from psutil import AIX
Expand Down Expand Up @@ -167,6 +168,22 @@ def test_proc_memory_maps(self):
self.assertEqual(hasit, False if OPENBSD or NETBSD or AIX else True)


# ===================================================================
# --- Test deprecations
# ===================================================================


class TestDeprecations(unittest.TestCase):

def test_memory_info_ex(self):
with warnings.catch_warnings(record=True) as ws:
psutil.Process().memory_info_ex()
w = ws[0]
self.assertIsInstance(w.category(), FutureWarning)
self.assertIn("memory_info_ex() is deprecated", str(w.message))
self.assertIn("use memory_info() instead", str(w.message))


# ===================================================================
# --- System API types
# ===================================================================
Expand Down

0 comments on commit c3767da

Please sign in to comment.