Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
This commit fixes the failing tests by catching a couple of missing
things from the update. The biggest fix was that for the --no-discover
case we still use a subprocess and because of that we need to tell
output.ReturnCodeToSubunit to that the input is not dynamic (and
therefore a Popen object) so it can handle that properly. The other
major change is that the return code tests are updated so that the
stdout and stderr from the subprocess calls are always decoded in the
non-subunit test cases. This was done primarily for ease of debugging,
but it also enabled the removal of several decode() calls when the
output is parsed.
  • Loading branch information
mtreinish committed Nov 24, 2019
1 parent 59189e6 commit 4196953
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 3 additions & 1 deletion stestr/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ def run_command(config='.stestr.conf', repo_type='file',
def run_tests():
run_proc = [('subunit', output.ReturnCodeToSubunit(
subprocess.Popen(run_cmd, shell=True,
stdout=subprocess.PIPE)))]
stdout=subprocess.PIPE),
dynamic=False))]

return load.load(in_streams=run_proc,
subunit_out=subunit_out,
repo_type=repo_type,
Expand Down
2 changes: 1 addition & 1 deletion stestr/tests/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _check_get_run_command(self, mock_sys, mock_TestProcessorFixture,
mock_TestProcessorFixture.assert_called_once_with(
None, command, "--list", "--load-list $IDFILE",
mock_get_repo_open.return_value, black_regex=None,
blacklist_file=None, concurrency=0,
blacklist_file=None, concurrency=0, dynamic=False,
group_callback=expected_group_callback,
test_filters=None, randomize=False, serial=False,
whitelist_file=None, worker_path=None)
Expand Down
17 changes: 9 additions & 8 deletions stestr/tests/test_return_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def assertRunExit(self, cmd, expected, subunit=False, stdin=None):
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
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))
Expand Down Expand Up @@ -296,14 +297,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.decode('utf-8'), '')
self.assertEqual(out, '')
# 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.decode('utf-8'), '')
self.assertEqual(err.decode('utf-8'), '')
self.assertEqual(out, '')
self.assertEqual(err, '')

def test_no_subunit_trace_force_subunit_trace(self):
out, err = self.assertRunExit(
Expand Down Expand Up @@ -393,29 +394,29 @@ 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.decode('utf8').splitlines()
lines = out.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.decode('utf8').splitlines()
lines = out.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.decode('utf8').splitlines()
lines = out.splitlines()
self.assertIn(' - Passed: 2', lines)
self.assertIn(' - Failed: 0', lines)
self.assertIn(' - Expected Fail: 1', lines)

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.decode('utf8').splitlines()
lines = out.splitlines()
self.assertIn(' - Passed: 0', lines)
self.assertIn(' - Failed: 2', lines)
self.assertIn(' - Unexpected Success: 1', lines)

0 comments on commit 4196953

Please sign in to comment.