From 89b00d714f66cf9cab9863c62978217bf811fed8 Mon Sep 17 00:00:00 2001 From: Pieter Mulder Date: Thu, 25 Jun 2015 14:53:54 +0200 Subject: [PATCH 1/3] deprecated_call dit not revert functions back to original Make sure that the warnings.warn and warnings.warn_explicit are reverted to there original function after running the function in deprecated_call --- _pytest/recwarn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index 482b78b0eb0..875cb510e75 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -45,8 +45,8 @@ def warn(*args, **kwargs): try: ret = func(*args, **kwargs) finally: - warnings.warn_explicit = warn_explicit - warnings.warn = warn + warnings.warn_explicit = oldwarn_explicit + warnings.warn = oldwarn if not l: __tracebackhide__ = True raise AssertionError("%r did not produce DeprecationWarning" %(func,)) From 444cdfe6e3ba1fb5788da9bb6778cfec76970be4 Mon Sep 17 00:00:00 2001 From: Pieter Mulder Date: Thu, 25 Jun 2015 17:33:40 +0200 Subject: [PATCH 2/3] Correct test_deprecated_call_preserves test. Test if we preserve the correct functions. --- testing/test_recwarn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index d8fe1784e54..d3455946fa4 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -64,12 +64,12 @@ def test_deprecated_call_ret(): assert ret == 42 def test_deprecated_call_preserves(): - r = py.std.warnings.onceregistry.copy() - f = py.std.warnings.filters[:] + warn = py.std.warnings.warn + warn_explicit = py.std.warnings.warn_explicit test_deprecated_call_raises() test_deprecated_call() - assert r == py.std.warnings.onceregistry - assert f == py.std.warnings.filters + assert warn == py.std.warnings.warn + assert warn_explicit == py.std.warnings.warn_explicit def test_deprecated_explicit_call_raises(): pytest.raises(AssertionError, From 75679f08c9622cc9112f2fa4dfd2f8d295cf6643 Mon Sep 17 00:00:00 2001 From: Pieter Mulder Date: Thu, 25 Jun 2015 17:38:45 +0200 Subject: [PATCH 3/3] Update AUTHORS and CHANGELOG --- AUTHORS | 1 + CHANGELOG | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index be4cd290dac..ca82b483f53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ Marc Schlaich Mark Abramowitz Martijn Faassen Nicolas Delaby +Pieter Mulder Piotr Banaszkiewicz Punyashloka Biswal Ralf Schmitt diff --git a/CHANGELOG b/CHANGELOG index 1023fd95f6c..88d21d68426 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ 2.7.2 (compared to 2.7.1) ----------------------------- +- preserve warning functions after call to pytest.deprecated_call + - fix issue767: pytest.raises value attribute does not contain the exception instance on Python 2.6. Thanks Eric Siegerman for providing the test case and Bruno Oliveira for PR.