summaryrefslogtreecommitdiff
path: root/src/mailman/config/tests
diff options
context:
space:
mode:
authorBarry Warsaw2014-12-16 03:37:26 -0500
committerBarry Warsaw2014-12-16 03:37:26 -0500
commit930516396f8aba9266c03b09065fed9fa3df2a0b (patch)
treead442a7d981f9d946f1e0c90b5f677863f707434 /src/mailman/config/tests
parent94247b82d1c030eac9be3eb4c461f830a99c2f63 (diff)
downloadmailman-930516396f8aba9266c03b09065fed9fa3df2a0b.tar.gz
mailman-930516396f8aba9266c03b09065fed9fa3df2a0b.tar.zst
mailman-930516396f8aba9266c03b09065fed9fa3df2a0b.zip
Make sure that TestConfigurationErrors doesn't break global state.
Diffstat (limited to 'src/mailman/config/tests')
-rw-r--r--src/mailman/config/tests/test_configuration.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/mailman/config/tests/test_configuration.py b/src/mailman/config/tests/test_configuration.py
index ce2e6bae3..f6bee4209 100644
--- a/src/mailman/config/tests/test_configuration.py
+++ b/src/mailman/config/tests/test_configuration.py
@@ -32,6 +32,7 @@ import mock
import tempfile
import unittest
+from contextlib import ExitStack
from mailman.config.config import (
Configuration, external_configuration, load_external)
from mailman.interfaces.configuration import (
@@ -108,8 +109,12 @@ layout: nonesuch
# Use a fake sys.exit() function that records that it was called, and
# that prevents further processing.
config = Configuration()
- # Suppress warning messages in the test output.
- with self.assertRaises(SystemExit) as cm, mock.patch('sys.stderr'):
+ # Suppress warning messages in the test output. Also, make sure that
+ # the config.load() call doesn't break global state.
+ with ExitStack() as resources:
+ resources.enter_context(mock.patch('sys.stderr'))
+ resources.enter_context(mock.patch.object(config, '_clear'))
+ cm = resources.enter_context(self.assertRaises(SystemExit))
config.load(filename)
self.assertEqual(cm.exception.args, (1,))
@@ -125,7 +130,11 @@ layout: nonesuch
log_dir: $nopath/log_dir
""", file=fp)
config = Configuration()
- # Suppress warning messages in the test output.
- with self.assertRaises(SystemExit) as cm, mock.patch('sys.stderr'):
+ # Suppress warning messages in the test output. Also, make sure that
+ # the config.load() call doesn't break global state.
+ with ExitStack() as resources:
+ resources.enter_context(mock.patch('sys.stderr'))
+ resources.enter_context(mock.patch.object(config, '_clear'))
+ cm = resources.enter_context(self.assertRaises(SystemExit))
config.load(filename)
self.assertEqual(cm.exception.args, (1,))