Merge pull request #201 from cdent/gabbi-run-fail-info
Adjust runner to track test suite failures
This commit is contained in:
commit
a1c7c82e69
@ -80,7 +80,8 @@ class ConciseTestResult(TextTestResult):
|
|||||||
self.stream.writeln('\t[unexpected success]')
|
self.stream.writeln('\t[unexpected success]')
|
||||||
|
|
||||||
def getDescription(self, test):
|
def getDescription(self, test):
|
||||||
name = test.test_data['name']
|
# Chop the test method ('test_request') off the test.id().
|
||||||
|
name = test.id().rsplit('.', 1)[0]
|
||||||
desc = test.test_data.get('desc', None)
|
desc = test.test_data.get('desc', None)
|
||||||
return ': '.join((name, desc)) if desc else name
|
return ': '.join((name, desc)) if desc else name
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
"""Implementation of a command-line runner for gabbi files (AKA suites)."""
|
"""Implementation of a command-line runner for gabbi files (AKA suites)."""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
import os
|
import os
|
||||||
@ -81,6 +83,8 @@ def run():
|
|||||||
verbosity = args.verbosity
|
verbosity = args.verbosity
|
||||||
failfast = args.failfast
|
failfast = args.failfast
|
||||||
failure = False
|
failure = False
|
||||||
|
# Keep track of file names that have failures.
|
||||||
|
failures = []
|
||||||
|
|
||||||
if not input_files:
|
if not input_files:
|
||||||
success = run_suite(sys.stdin, handler_objects, host, port,
|
success = run_suite(sys.stdin, handler_objects, host, port,
|
||||||
@ -89,22 +93,28 @@ def run():
|
|||||||
failure = not success
|
failure = not success
|
||||||
else:
|
else:
|
||||||
for input_file in input_files:
|
for input_file in input_files:
|
||||||
|
name = os.path.splitext(os.path.basename(input_file))[0]
|
||||||
with open(input_file, 'r') as fh:
|
with open(input_file, 'r') as fh:
|
||||||
data_dir = os.path.dirname(input_file)
|
data_dir = os.path.dirname(input_file)
|
||||||
success = run_suite(fh, handler_objects, host, port,
|
success = run_suite(fh, handler_objects, host, port,
|
||||||
prefix, force_ssl, failfast,
|
prefix, force_ssl, failfast,
|
||||||
data_dir=data_dir,
|
data_dir=data_dir,
|
||||||
verbosity=verbosity)
|
verbosity=verbosity, name=name)
|
||||||
|
if not success:
|
||||||
|
failures.append(input_file)
|
||||||
if not failure: # once failed, this is considered immutable
|
if not failure: # once failed, this is considered immutable
|
||||||
failure = not success
|
failure = not success
|
||||||
if failure and failfast:
|
if failure and failfast:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if failures:
|
||||||
|
print("There were failures in the following files:", file=sys.stderr)
|
||||||
|
print('\n'.join(failures), file=sys.stderr)
|
||||||
sys.exit(failure)
|
sys.exit(failure)
|
||||||
|
|
||||||
|
|
||||||
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
||||||
failfast=False, data_dir='.', verbosity=False):
|
failfast=False, data_dir='.', verbosity=False, name='input'):
|
||||||
"""Run the tests from the YAML in handle."""
|
"""Run the tests from the YAML in handle."""
|
||||||
data = utils.load_yaml(handle)
|
data = utils.load_yaml(handle)
|
||||||
if force_ssl:
|
if force_ssl:
|
||||||
@ -120,8 +130,8 @@ def run_suite(handle, handler_objects, host, port, prefix, force_ssl=False,
|
|||||||
|
|
||||||
loader = unittest.defaultTestLoader
|
loader = unittest.defaultTestLoader
|
||||||
test_suite = suitemaker.test_suite_from_dict(
|
test_suite = suitemaker.test_suite_from_dict(
|
||||||
loader, 'input', data, data_dir, host, port, None, None, prefix=prefix,
|
loader, name, data, data_dir, host, port, None, None, prefix=prefix,
|
||||||
handlers=handler_objects)
|
handlers=handler_objects, test_loader_name='gabbi-runner')
|
||||||
|
|
||||||
result = ConciseTestRunner(
|
result = ConciseTestRunner(
|
||||||
verbosity=2, failfast=failfast).run(test_suite)
|
verbosity=2, failfast=failfast).run(test_suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user