process = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
- for line in iter(process.stdout.readline, ''):
+ for line in iter(process.stdout.readline, b''):
if console:
- sys.stdout.write(line)
- f_stdout.write(line)
+ sys.stdout.write(line.decode("utf-8"))
+ f_stdout.write(line.decode("utf-8"))
process.wait()
with open(self.result_file, 'r') as f_stdin:
self.__logger.debug("$ %s\n%s", cmd, f_stdin.read().rstrip())
stats = subprocess.Popen(
['subunit-stats'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output, _ = stats.communicate(stream.read())
- cls.__logger.info("\n\n%s", output)
+ cls.__logger.info("\n\n%s", output.decode("utf-8"))
def generate_xunit(self, stream):
"""Generate junit report from subunit stream
['subunit2junitxml'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
output, _ = stats.communicate(stream.read())
- xml.write(output)
+ xml.write(output.decode("utf-8"))
def generate_html(self, stream):
"""Generate html report from subunit stream
self.start_time = time.time()
if not os.path.isdir(self.res_dir):
os.makedirs(self.res_dir)
- stream = six.StringIO()
+ stream = six.BytesIO()
result = SubunitTestRunner(
stream=stream, verbosity=2).run(self.suite).decorated
self.generate_stats(stream)
self.generate_xunit(stream)
- with open('{}/subunit_stream'.format(self.res_dir), 'w') as subfd:
+ with open('{}/subunit_stream'.format(self.res_dir), 'wb') as subfd:
stream.seek(0)
shutil.copyfileobj(stream, subfd)
self.generate_html('{}/subunit_stream'.format(self.res_dir))
return_value=mock.Mock(
communicate=mock.Mock(return_value=("foo", "bar"))))
def test_generate_xunit_ok(self, *args):
- stream = six.StringIO()
+ stream = six.BytesIO()
with mock.patch('six.moves.builtins.open',
mock.mock_open()) as mock_open:
self.psrunner.generate_xunit(stream)
with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(), status)
m_open.assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir), 'w')
+ '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
self.assertEqual(self.psrunner.is_successful(), result)
args[0].assert_called_once_with(self.psrunner.suite)
args[1].assert_not_called()
with mock.patch('six.moves.builtins.open', mock.mock_open()) as m_open:
self.assertEqual(self.psrunner.run(name=name), status)
m_open.assert_called_once_with(
- '{}/subunit_stream'.format(self.psrunner.res_dir), 'w')
+ '{}/subunit_stream'.format(self.psrunner.res_dir), 'wb')
self.assertEqual(self.psrunner.is_successful(), result)
args[0].assert_called_once_with(self.psrunner.suite)
args[1].assert_called_once_with()