[pypy-commit] pypy default: Don't mess up the warnings module for subsequent tests
rlamy
pypy.commits at gmail.com
Fri Nov 16 11:54:44 EST 2018
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r95323:ce46c3cdcf72
Date: 2018-11-16 16:53 +0000
http://bitbucket.org/pypy/pypy/changeset/ce46c3cdcf72/
Log: Don't mess up the warnings module for subsequent tests
diff --git a/pypy/module/_warnings/test/test_warnings.py b/pypy/module/_warnings/test/test_warnings.py
--- a/pypy/module/_warnings/test/test_warnings.py
+++ b/pypy/module/_warnings/test/test_warnings.py
@@ -46,18 +46,22 @@
except ImportError:
skip('no test, -A on cpython?')
# With showarning() missing, make sure that output is okay.
- del warnings.showwarning
+ saved = warnings.showwarning
+ try:
+ del warnings.showwarning
- stderr = sys.stderr
- try:
- sys.stderr = StringIO.StringIO()
- inner('test message')
- result = sys.stderr.getvalue()
+ stderr = sys.stderr
+ try:
+ sys.stderr = StringIO.StringIO()
+ inner('test message')
+ result = sys.stderr.getvalue()
+ finally:
+ sys.stderr = stderr
+
+ assert result.count('\n') == 2
+ assert ' warnings.warn(message, ' in result
finally:
- sys.stderr = stderr
-
- assert result.count('\n') == 2
- assert ' warnings.warn(message, ' in result
+ warnings.showwarning = saved
def test_filename_none(self):
import _warnings
More information about the pypy-commit
mailing list