diff --git a/os_testr/subunit_trace.py b/os_testr/subunit_trace.py index 315d850..1e9b51d 100755 --- a/os_testr/subunit_trace.py +++ b/os_testr/subunit_trace.py @@ -354,6 +354,12 @@ def main(): print_fails(sys.stdout) if not args.no_summary: print_summary(sys.stdout, elapsed_time) + + # NOTE(mtreinish): Ideally this should live in testtools streamSummary + # this is just in place until the behavior lands there (if it ever does) + if count_tests('status', '^success$') == 0: + print("\nNo tests were successful during the run") + exit(1) exit(0 if summary.wasSuccessful() else 1) diff --git a/os_testr/tests/sample_streams/all_skips.subunit b/os_testr/tests/sample_streams/all_skips.subunit new file mode 100644 index 0000000..54156b5 Binary files /dev/null and b/os_testr/tests/sample_streams/all_skips.subunit differ diff --git a/os_testr/tests/sample_streams/successful.subunit b/os_testr/tests/sample_streams/successful.subunit new file mode 100644 index 0000000..6f3b664 Binary files /dev/null and b/os_testr/tests/sample_streams/successful.subunit differ diff --git a/os_testr/tests/test_subunit_trace.py b/os_testr/tests/test_subunit_trace.py index 5544636..736dff9 100644 --- a/os_testr/tests/test_subunit_trace.py +++ b/os_testr/tests/test_subunit_trace.py @@ -14,6 +14,8 @@ # under the License. from datetime import datetime as dt +import os +import subprocess from ddt import data from ddt import ddt @@ -59,3 +61,21 @@ class TestSubunitTrace(base.TestCase): } with patch.dict(subunit_trace.RESULTS, patched_res, clear=True): self.assertEqual(subunit_trace.run_time(), expected_result) + + def test_return_code_all_skips(self): + skips_stream = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'sample_streams/all_skips.subunit') + p = subprocess.Popen(['subunit-trace'], stdin=subprocess.PIPE) + with open(skips_stream, 'rb') as stream: + p.communicate(stream.read()) + self.assertEqual(1, p.returncode) + + def test_return_code_normal_run(self): + regular_stream = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'sample_streams/successful.subunit') + p = subprocess.Popen(['subunit-trace'], stdin=subprocess.PIPE) + with open(regular_stream, 'rb') as stream: + p.communicate(stream.read()) + self.assertEqual(0, p.returncode)