From 6378cdf7a915b7c5f26cf2c9fa0ca204758f039f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 26 Nov 2015 15:54:57 -0200 Subject: [PATCH] Restored 2.7 implentation of deprecated_call --- _pytest/recwarn.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index 601acffda..129d8250c 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -29,18 +29,29 @@ def pytest_namespace(): def deprecated_call(func, *args, **kwargs): - """Assert that ``func(*args, **kwargs)`` triggers a DeprecationWarning. + """ assert that calling ``func(*args, **kwargs)`` + triggers a DeprecationWarning. """ - wrec = WarningsRecorder() - with wrec: - warnings.simplefilter('always') # ensure all warnings are triggered + l = [] + oldwarn_explicit = getattr(warnings, 'warn_explicit') + def warn_explicit(*args, **kwargs): + l.append(args) + oldwarn_explicit(*args, **kwargs) + oldwarn = getattr(warnings, 'warn') + def warn(*args, **kwargs): + l.append(args) + oldwarn(*args, **kwargs) + + warnings.warn_explicit = warn_explicit + warnings.warn = warn + try: ret = func(*args, **kwargs) - - depwarnings = (DeprecationWarning, PendingDeprecationWarning) - if not any(r.category in depwarnings for r in wrec): + finally: + warnings.warn_explicit = oldwarn_explicit + warnings.warn = oldwarn + if not l: __tracebackhide__ = True - raise AssertionError("%r did not produce DeprecationWarning" % (func,)) - + raise AssertionError("%r did not produce DeprecationWarning" %(func,)) return ret