From 5d6fa6bfc673600afc1a029751c9d66dbc98e694 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Sun, 6 Oct 2019 19:13:53 -0400 Subject: [PATCH] Clean up test_return_code tests slightly This is a refinement on the previous commit to reduce unecessary changes to the functional tests in the test_return_codes module. Mainly always decoding the output from the subprocess for testing broken things unexpectedly when a bytes object was expected. --- stestr/tests/test_return_codes.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/stestr/tests/test_return_codes.py b/stestr/tests/test_return_codes.py index df14a09b..9730d4b9 100644 --- a/stestr/tests/test_return_codes.py +++ b/stestr/tests/test_return_codes.py @@ -81,25 +81,21 @@ def _add_dict(test): self.assertThat(len(tests), testtools.matchers.GreaterThan(0)) def assertRunExit(self, cmd, expected, subunit=False, stdin=None): - env = os.environ if stdin: p = subprocess.Popen( "%s" % cmd, shell=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - env=env) + stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate(stdin) else: p = subprocess.Popen( "%s" % cmd, shell=True, - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - env=env) + stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if not subunit: - out = out.decode('utf8') - err = err.decode('utf8') self.assertEqual( p.returncode, expected, - "Stdout: %s; Stderr: %s" % (out, err)) + "Stdout: %s; Stderr: %s" % (out.decode('utf8'), + err.decode('utf8'))) return (out, err) else: self.assertEqual(p.returncode, expected, @@ -239,10 +235,8 @@ def test_list(self): self.assertRunExit('stestr list', 0) def _get_cmd_stdout(self, cmd): - env = os.environ p = subprocess.Popen(cmd, shell=True, - stdout=subprocess.PIPE, - env=env) + stdout=subprocess.PIPE) out = p.communicate() self.assertEqual(0, p.returncode) return out @@ -297,14 +291,14 @@ def test_load_force_init_invalid(self): def test_load_from_stdin_quiet(self): out, err = self.assertRunExit('stestr --user-config stestr.yaml -q ' 'run passing', 0) - self.assertEqual(out, '') + self.assertEqual('', out.decode('utf-8')) # FIXME(masayukig): We get some warnings when we run a coverage job. # So, just ignore 'err' here. stream = self._get_cmd_stdout('stestr last --subunit')[0] out, err = self.assertRunExit('stestr --user-config stestr.yaml -q ' 'load', 0, stdin=stream) - self.assertEqual(out, '') - self.assertEqual(err, '') + self.assertEqual(out.decode('utf-8'), '') + self.assertEqual(err.decode('utf-8'), '') def test_no_subunit_trace_force_subunit_trace(self): out, err = self.assertRunExit( @@ -394,21 +388,21 @@ def test_list_from_func(self): def test_run_no_discover_pytest_path(self): passing_string = 'tests/test_passing.py::FakeTestClass::test_pass_list' out, err = self.assertRunExit('stestr run -n %s' % passing_string, 0) - lines = out.splitlines() + lines = out.decode('utf8').splitlines() self.assertIn(' - Passed: 1', lines) self.assertIn(' - Failed: 0', lines) def test_run_no_discover_pytest_path_failing(self): passing_string = 'tests/test_failing.py::FakeTestClass::test_pass_list' out, err = self.assertRunExit('stestr run -n %s' % passing_string, 1) - lines = out.splitlines() + lines = out.decode('utf8').splitlines() self.assertIn(' - Passed: 0', lines) self.assertIn(' - Failed: 1', lines) def test_run_no_discover_file_path(self): passing_string = 'tests/test_passing.py' out, err = self.assertRunExit('stestr run -n %s' % passing_string, 0) - lines = out.splitlines() + lines = out.decode('utf8').splitlines() self.assertIn(' - Passed: 2', lines) self.assertIn(' - Failed: 0', lines) self.assertIn(' - Expected Fail: 1', lines) @@ -416,7 +410,7 @@ def test_run_no_discover_file_path(self): def test_run_no_discover_file_path_failing(self): passing_string = 'tests/test_failing.py' out, err = self.assertRunExit('stestr run -n %s' % passing_string, 1) - lines = out.splitlines() + lines = out.decode('utf8').splitlines() self.assertIn(' - Passed: 0', lines) self.assertIn(' - Failed: 2', lines) self.assertIn(' - Unexpected Success: 1', lines)