Fail if no tests were successfully executed

This commit adds another sanity check to ensure we didn't have a test
run with just skipped tests.

Change-Id: Ie4bd185c209d9e9230ca8a3f54e8a433e82d9c14
This commit is contained in:
Matthew Treinish 2015-11-18 10:14:10 -05:00
parent 01fb487df1
commit 2a22826c58
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
4 changed files with 26 additions and 0 deletions

View File

@ -354,6 +354,12 @@ def main():
print_fails(sys.stdout) print_fails(sys.stdout)
if not args.no_summary: if not args.no_summary:
print_summary(sys.stdout, elapsed_time) 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) exit(0 if summary.wasSuccessful() else 1)

Binary file not shown.

Binary file not shown.

View File

@ -14,6 +14,8 @@
# under the License. # under the License.
from datetime import datetime as dt from datetime import datetime as dt
import os
import subprocess
from ddt import data from ddt import data
from ddt import ddt from ddt import ddt
@ -59,3 +61,21 @@ class TestSubunitTrace(base.TestCase):
} }
with patch.dict(subunit_trace.RESULTS, patched_res, clear=True): with patch.dict(subunit_trace.RESULTS, patched_res, clear=True):
self.assertEqual(subunit_trace.run_time(), expected_result) 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)