Created
March 3, 2013 21:01
-
-
Save jszakmeister/5078271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/functional_tests/test_multiprocessing/test_keyboardinterrupt.py b/functional_tests/test_multiprocessing/test_keyboardinterrupt.py | |
index 8f07e54..86452a9 100644 | |
--- a/functional_tests/test_multiprocessing/test_keyboardinterrupt.py | |
+++ b/functional_tests/test_multiprocessing/test_keyboardinterrupt.py | |
@@ -25,9 +25,12 @@ runner = os.path.join(support, 'fake_nosetest.py') | |
def keyboardinterrupt(case): | |
#os.setsid would create a process group so signals sent to the | |
#parent process will propogates to all children processes | |
- from tempfile import mktemp | |
+ from tempfile import mktemp, TemporaryFile | |
logfile = mktemp() | |
- process = Popen([sys.executable,runner,os.path.join(support,case),logfile], preexec_fn=os.setsid, stdout=PIPE, stderr=PIPE, bufsize=-1) | |
+ tmpStdout = TemporaryFile() | |
+ tmpStderr = TemporaryFile() | |
+ process = Popen([sys.executable,runner,os.path.join(support,case),logfile], | |
+ preexec_fn=os.setsid, stdout=tmpStdout, stderr=tmpStderr) | |
#wait until logfile is created: | |
retry=100 | |
@@ -37,8 +40,20 @@ def keyboardinterrupt(case): | |
if not retry: | |
raise Exception('Timeout while waiting for log file to be created by fake_nosetest.py') | |
+ sleep(0.1) | |
os.killpg(process.pid, signal.SIGINT) | |
- return process, logfile | |
+ | |
+ return (process, tmpStdout, tmpStderr), logfile | |
+ | |
+def get_stdout_stderr(process): | |
+ process, tmpStdout, tmpStderr = process | |
+ | |
+ retcode = process.wait() | |
+ tmpStdout.seek(0) | |
+ tmpStderr.seek(0) | |
+ stdout = tmpStdout.read().decode('utf-8') | |
+ stderr = tmpStderr.read().decode('utf-8') | |
+ return stdout, stderr | |
def get_log_content(logfile): | |
'''prefix = 'tempfile is: ' | |
@@ -53,9 +68,14 @@ def get_log_content(logfile): | |
def test_keyboardinterrupt(): | |
process, logfile = keyboardinterrupt('keyboardinterrupt.py') | |
- stdout, stderr = [s.decode('utf-8') for s in process.communicate(None)] | |
- print stderr | |
+ stdout, stderr = get_stdout_stderr(process) | |
log = get_log_content(logfile) | |
+ print "---- log ----" | |
+ print log | |
+ print "---- captured stdout ----" | |
+ print stdout | |
+ print "---- captured stderr ----" | |
+ print stderr | |
assert 'setup' in log | |
assert 'test_timeout' in log | |
assert 'test_timeout_finished' not in log | |
@@ -70,9 +90,15 @@ def test_keyboardinterrupt(): | |
def test_keyboardinterrupt_twice(): | |
process, logfile = keyboardinterrupt('keyboardinterrupt_twice.py') | |
sleep(0.5) | |
- os.killpg(process.pid, signal.SIGINT) | |
- stdout, stderr = [s.decode('utf-8') for s in process.communicate(None)] | |
+ os.killpg(process[0].pid, signal.SIGINT) | |
+ stdout, stderr = get_stdout_stderr(process) | |
log = get_log_content(logfile) | |
+ print "---- log ----" | |
+ print log | |
+ print "---- captured stdout ----" | |
+ print stdout | |
+ print "---- captured stderr ----" | |
+ print stderr | |
assert 'setup' in log | |
assert 'test_timeout' in log | |
assert 'test_timeout_finished' not in log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment