C
Chris Withers
Hi All,
I have this simple function:
def execute(command):
process = Popen(command.split(),stderr=STDOUT,stdout=PIPE)
return process.communicate()[0]
...but my unit test for it fails:
from testfixtures import tempdir,compare
from unittest import TestCase
class TestExecute(TestCase):
@tempdir()
def test_out_and_err(self,d):
path = d.write('test.py','\n'.join((
"import sys",
"sys.stdout.write('stdout\\n')",
"sys.stderr.write('stderr\\n')",
"sys.stdout.write('stdout2\\n')",
)),path=True)
compare('stdout\nstderr\nstdout2\n',
execute(sys.executable+' '+path))
....because:
AssertionError:
@@ -1,4 +1,4 @@
-stdout
-stderr
-stdout2
+stdout
+stdout2
+stderr
....the order of the writes isn't preserved.
How can I get this to be the case?
Chris
I have this simple function:
def execute(command):
process = Popen(command.split(),stderr=STDOUT,stdout=PIPE)
return process.communicate()[0]
...but my unit test for it fails:
from testfixtures import tempdir,compare
from unittest import TestCase
class TestExecute(TestCase):
@tempdir()
def test_out_and_err(self,d):
path = d.write('test.py','\n'.join((
"import sys",
"sys.stdout.write('stdout\\n')",
"sys.stderr.write('stderr\\n')",
"sys.stdout.write('stdout2\\n')",
)),path=True)
compare('stdout\nstderr\nstdout2\n',
execute(sys.executable+' '+path))
....because:
AssertionError:
@@ -1,4 +1,4 @@
-stdout
-stderr
-stdout2
+stdout
+stdout2
+stderr
....the order of the writes isn't preserved.
How can I get this to be the case?
Chris