[Python-checkins] distutils2: better way for testing for warnings
tarek.ziade
python-checkins at python.org
Sun Sep 19 10:20:22 CEST 2010
tarek.ziade pushed fb6896cb6a5c to distutils2:
http://hg.python.org/distutils2/rev/fb6896cb6a5c
changeset: 627:fb6896cb6a5c
user: Konrad Delong <konryd at gmail.com>
date: Sun Aug 15 00:00:16 2010 +0200
summary: better way for testing for warnings
files: src/distutils2/tests/test_test.py, src/distutils2/tests/with_support.py
diff --git a/src/distutils2/tests/test_test.py b/src/distutils2/tests/test_test.py
--- a/src/distutils2/tests/test_test.py
+++ b/src/distutils2/tests/test_test.py
@@ -3,6 +3,7 @@
import sys
import shutil
import subprocess
+import warnings
from copy import copy
from os.path import join
@@ -120,17 +121,22 @@
@unittest.skipUnless(sys.version > '2.6', 'Need >= 2.6')
def test_checks_requires(self):
- from distutils2.tests.with_support import examine_warnings
dist = Distribution()
cmd = test(dist)
- def examinator(ws):
+ record = []
+ orig_showwarning = warnings.showwarning
+ def record_showwarning(*args):
+ record.append(args)
+ return orig_showwarning(*args)
+ try:
+ warnings.showwarning = record_showwarning
cmd.tests_require = ['ohno_ohno-impossible_1234-name_stop-that!']
cmd.ensure_finalized()
- self.assertEqual(1, len(ws))
- warning = ws[0]
- self.assertIs(warning.category, RuntimeWarning)
-
- examine_warnings(examinator)
+ self.assertEqual(1, len(record))
+ warning = record[0]
+ self.assertIs(warning[1], RuntimeWarning)
+ finally:
+ warnings.showwarning = orig_showwarning
def test_custom_runner(self):
dist = Distribution()
diff --git a/src/distutils2/tests/with_support.py b/src/distutils2/tests/with_support.py
deleted file mode 100644
--- a/src/distutils2/tests/with_support.py
+++ /dev/null
@@ -1,7 +0,0 @@
-def examine_warnings(examinator):
- """Given an examinator function calls it as if the code was under with
- catch_warnings block. Useful for testing older Python versions"""
- import warnings
- warnings.simplefilter('default')
- with warnings.catch_warnings(record=True) as ws:
- examinator(ws)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list