diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2009-04-11 13:31:31 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2009-04-11 13:31:31 (GMT) |
commit | cd2e7042ae7d2ebd27c26c36aef9b761b1f9d22f (patch) | |
tree | 43881c01cee15dd9699c1153de28fda0d3d275b3 /Lib/test/test_warnings.py | |
parent | b524825788847ac28d0bb56ea3c33d52bfe6798d (diff) | |
download | cpython-cd2e7042ae7d2ebd27c26c36aef9b761b1f9d22f.zip cpython-cd2e7042ae7d2ebd27c26c36aef9b761b1f9d22f.tar.gz cpython-cd2e7042ae7d2ebd27c26c36aef9b761b1f9d22f.tar.bz2 |
Issue 5354: Provide a standardised testing mechanism for doing fresh imports of modules, including the ability to block extension modules in order to test the pure Python fallbacks
Diffstat (limited to 'Lib/test/test_warnings.py')
-rw-r--r-- | Lib/test/test_warnings.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index bb2fb5f..4c3b43a 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -10,18 +10,8 @@ import warning_tests import warnings as original_warnings -sys.modules['_warnings'] = 0 -del sys.modules['warnings'] - -import warnings as py_warnings - -del sys.modules['_warnings'] -del sys.modules['warnings'] - -import warnings as c_warnings - -sys.modules['warnings'] = original_warnings - +py_warnings = test_support.import_fresh_module('warnings', ['_warnings']) +c_warnings = test_support.import_fresh_module('warnings') @contextmanager def warnings_state(module): @@ -341,9 +331,21 @@ class WarnTests(unittest.TestCase): class CWarnTests(BaseTest, WarnTests): module = c_warnings + # As an early adopter, we sanity check the + # test_support.import_fresh_module utility function + def test_accelerated(self): + self.assertFalse(original_warnings is self.module) + self.assertFalse(hasattr(self.module.warn, 'func_code')) + class PyWarnTests(BaseTest, WarnTests): module = py_warnings + # As an early adopter, we sanity check the + # test_support.import_fresh_module utility function + def test_pure_python(self): + self.assertFalse(original_warnings is self.module) + self.assertTrue(hasattr(self.module.warn, 'func_code')) + class WCmdLineTests(unittest.TestCase): |