Skip to content

Commit fff2507

Browse files
committed
first_stage_test: Make sure the test result is always the same
Make sure the test result does not change, only because the MITOGEN_LOG_LEVEL in the test environment is different. Signed-off-by: Marc Hartmayer <[email protected]>
1 parent a0c0b2d commit fff2507

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/first_stage_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
import subprocess
22

3+
try:
4+
from io import StringIO
5+
except ImportError:
6+
from StringIO import StringIO
7+
38
import testlib
49

510
import mitogen.core
611
import mitogen.parent
712
from mitogen.core import b
813

914

15+
class redirect(object):
16+
def __init__(self, name, new):
17+
self._name = name
18+
self._new = new
19+
self._old = None
20+
21+
def __enter__(self):
22+
self._old = getattr(
23+
sys,
24+
self._name,
25+
)
26+
setattr(sys, self._name, self._new)
27+
return self._new
28+
29+
def __exit__(self, exc_type, exc_val, exc_tb):
30+
setattr(sys, self._name, self._old)
31+
return False
32+
33+
1034
class CommandLineTest(testlib.RouterMixin, testlib.TestCase):
1135
# Ensure this version of Python produces a command line that is sufficient
1236
# to bootstrap this version of Python.
@@ -17,13 +41,21 @@ class CommandLineTest(testlib.RouterMixin, testlib.TestCase):
1741
# * 3.x starting 2.7
1842

1943
def setUp(self):
44+
# Make sure we set-up the logger before the Broker is created
45+
with redirect('stderr', StringIO()) as f:
46+
mitogen.utils.log_to_file(level="DEBUG")
2047
super(CommandLineTest, self).setUp()
2148
options = mitogen.parent.Options(max_message_size=123)
2249
conn = mitogen.parent.Connection(options, self.router)
2350
conn.context = mitogen.core.Context(None, 123)
2451
self.args = conn.get_boot_command()
2552
self.preamble = conn.get_preamble()
2653
self.conn = conn
54+
self.stderr = f
55+
56+
def tearDown(self):
57+
super(CommandLineTest, self).tearDown()
58+
mitogen.utils.log_to_file()
2759

2860
def test_valid_syntax(self):
2961
"""Test valid syntax

0 commit comments

Comments
 (0)