summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-02 22:07:47 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-02 22:07:47 (GMT)
commit1c4055208758c6e85f00674eae24e0351b659c5a (patch)
tree3f64d0c743ce9ab3efa8ceb3376cd1fc2d998d01
parent5b6b4a8c344cb70dca67109989f430733c74cfce (diff)
downloadcpython-1c4055208758c6e85f00674eae24e0351b659c5a.zip
cpython-1c4055208758c6e85f00674eae24e0351b659c5a.tar.gz
cpython-1c4055208758c6e85f00674eae24e0351b659c5a.tar.bz2
Fix test_warnings: don't modify warnings.filters
BaseTest now ensures that unittest.TestCase.assertWarns() uses the same warnings module than warnings.catch_warnings(). Otherwise, warnings.catch_warnings() will be unable to remove the added filter.
-rw-r--r--Lib/test/test_warnings.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index ddcea8e..b519f0a 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -44,6 +44,7 @@ class BaseTest:
"""Basic bookkeeping required for testing."""
def setUp(self):
+ self.old_unittest_module = unittest.case.warnings
# The __warningregistry__ needs to be in a pristine state for tests
# to work properly.
if '__warningregistry__' in globals():
@@ -55,10 +56,15 @@ class BaseTest:
# The 'warnings' module must be explicitly set so that the proper
# interaction between _warnings and 'warnings' can be controlled.
sys.modules['warnings'] = self.module
+ # Ensure that unittest.TestCase.assertWarns() uses the same warnings
+ # module than warnings.catch_warnings(). Otherwise,
+ # warnings.catch_warnings() will be unable to remove the added filter.
+ unittest.case.warnings = self.module
super(BaseTest, self).setUp()
def tearDown(self):
sys.modules['warnings'] = original_warnings
+ unittest.case.warnings = self.old_unittest_module
super(BaseTest, self).tearDown()
class PublicAPITests(BaseTest):