Skip to content

Commit

Permalink
Merge pull request #158 from mtreinish/supress-stdout-attach
Browse files Browse the repository at this point in the history
Add option to suppress attachment printing on successful tests
  • Loading branch information
masayukig committed Apr 10, 2018
2 parents 22d74d0 + 1316ebd commit 4470ba0
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 31 deletions.
3 changes: 3 additions & 0 deletions doc/source/MANUAL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,19 @@ that changes the default on all available options in the config file is::
color: True
abbreviate: True
slowest: True
suppress-attachments: True
failing:
list: True
last:
no-subunit-trace: True
color: True
suppress-attachments: True
load:
force-init: True
subunit-trace: True
color: True
abbreviate: True
suppress-attachments: True

If you choose to use a user config file you can specify any subset of the
options and commands you choose.
Expand Down
19 changes: 16 additions & 3 deletions stestr/commands/last.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def get_parser(self, prog_name):
'output, if subunit-trace output is enabled. '
'(this is the default). If subunit-trace is '
'disable this does nothing.')
parser.add_argument('--suppress-attachments', action='store_true',
dest='suppress_attachments',
help='If set do not print stdout or stderr '
'attachment contents on a successful test '
'execution')
return parser

def take_action(self, parsed_args):
Expand All @@ -70,17 +75,22 @@ def take_action(self, parsed_args):
pretty_out = False
pretty_out = args.force_subunit_trace or pretty_out
color = args.color or user_conf.last.get('color', False)
suppress_attachments = (
args.suppress_attachments or user_conf.last.get(
'suppress-attachments', False))

else:
pretty_out = args.force_subunit_trace or not args.no_subunit_trace
color = args.color
suppress_attachments = args.suppress_attachments
return last(repo_type=self.app_args.repo_type,
repo_url=self.app_args.repo_url,
subunit_out=args.subunit, pretty_out=pretty_out,
color=color)
color=color, suppress_attachments=suppress_attachments)


def last(repo_type='file', repo_url=None, subunit_out=False, pretty_out=True,
color=False, stdout=sys.stdout):
color=False, stdout=sys.stdout, suppress_attachments=False):
"""Show the last run loaded into a a repository
This function will print the results from the last run in the repository
Expand All @@ -100,6 +110,8 @@ def last(repo_type='file', repo_url=None, subunit_out=False, pretty_out=True,
:param bool subunit: Show output as a subunit stream.
:param file stdout: The output file to write all output to. By default
this is sys.stdout
:param bool suppress_attachments: When set true attachments subunit_trace
will not print attachments on successful test execution.
:return return_code: The exit code for the command. 0 for success and > 0
for failures.
Expand Down Expand Up @@ -146,7 +158,8 @@ def last(repo_type='file', repo_url=None, subunit_out=False, pretty_out=True,
else:
stream = latest_run.get_subunit_stream()
failed = subunit_trace.trace(stream, stdout, post_fails=True,
color=color)
color=color,
suppress_attachments=suppress_attachments)
if failed:
return 1
else:
Expand Down
19 changes: 16 additions & 3 deletions stestr/commands/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def get_parser(self, prog_name):
parser.add_argument('--abbreviate', action='store_true',
dest='abbreviate',
help='Print one character status for each test')
parser.add_argument('--suppress-attachments', action='store_true',
dest='suppress_attachments',
help='If set do not print stdout or stderr '
'attachment contents on a successful test '
'execution')
return parser

def get_description(self):
Expand All @@ -84,25 +89,30 @@ def take_action(self, parsed_args):
color = args.color or user_conf.load.get('color', False)
abbreviate = args.abbreviate or user_conf.load.get('abbreviate',
False)
suppress_attachments = (
args.suppress_attachments or user_conf.load.get(
'suppress-attachments', False))
else:
force_init = args.force_init
pretty_out = args.subunit_trace
color = args.color
abbreviate = args.abbreviate
suppress_attachments = args.suppress_attachments
verbose_level = self.app.options.verbose_level
stdout = open(os.devnull, 'w') if verbose_level == 0 else sys.stdout
load(repo_type=self.app_args.repo_type,
repo_url=self.app_args.repo_url,
partial=args.partial, subunit_out=args.subunit,
force_init=force_init, streams=args.files,
pretty_out=pretty_out, color=color,
stdout=stdout, abbreviate=abbreviate)
stdout=stdout, abbreviate=abbreviate,
suppress_attachments=suppress_attachments)


def load(force_init=False, in_streams=None,
partial=False, subunit_out=False, repo_type='file', repo_url=None,
run_id=None, streams=None, pretty_out=False, color=False,
stdout=sys.stdout, abbreviate=False):
stdout=sys.stdout, abbreviate=False, suppress_attachments=False):
"""Load subunit streams into a repository
This function will load subunit streams into the repository. It will
Expand All @@ -129,6 +139,8 @@ def load(force_init=False, in_streams=None,
:param file stdout: The output file to write all output to. By default
this is sys.stdout
:param bool abbreviate: Use abbreviated output if set true
:param bool suppress_attachments: When set true attachments subunit_trace
will not print attachments on successful test execution.
:return return_code: The exit code for the command. 0 for success and > 0
for failures.
Expand Down Expand Up @@ -179,7 +191,8 @@ def make_tests():
elif pretty_out:
outcomes = testtools.StreamToDict(
functools.partial(subunit_trace.show_outcome, stdout,
enable_color=color, abbreviate=abbreviate))
enable_color=color, abbreviate=abbreviate,
suppress_attachments=suppress_attachments))
summary_result = testtools.StreamSummary()
output_result = testtools.CopyStreamResult([outcomes, summary_result])
output_result = testtools.StreamResultRouter(output_result)
Expand Down
45 changes: 27 additions & 18 deletions stestr/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ def get_parser(self, prog_name):
parser.add_argument('--abbreviate', action='store_true',
dest='abbreviate',
help='Print one character status for each test')
parser.add_argument('--suppress-attachments', action='store_true',
dest='suppress_attachments',
help='If set do not print stdout or stderr '
'attachment contents on a successful test '
'execution')
return parser

def get_description(self):
Expand Down Expand Up @@ -154,12 +159,16 @@ def take_action(self, parsed_args):
color = args.color or user_conf.run.get('color', False)
abbreviate = args.abbreviate = user_conf.run.get(
'abbreviate', False)
suppress_attachments = (
args.suppress_attachments or user_conf.run.get(
'suppress-attachments', False))
else:
pretty_out = args.force_subunit_trace or not args.no_subunit_trace
concurrency = args.concurrency or 0
random = args.random
color = args.color
abbreviate = args.abbreviate
suppress_attachments = args.suppress_attachments
verbose_level = self.app.options.verbose_level
stdout = open(os.devnull, 'w') if verbose_level == 0 else sys.stdout
result = run_command(
Expand All @@ -176,7 +185,8 @@ def take_action(self, parsed_args):
no_discover=args.no_discover, random=random,
combine=args.combine,
filters=filters, pretty_out=pretty_out, color=color,
stdout=stdout, abbreviate=abbreviate)
stdout=stdout, abbreviate=abbreviate,
suppress_attachments=suppress_attachments)

# Always output slowest test info if requested, regardless of other
# test run options
Expand Down Expand Up @@ -216,7 +226,7 @@ def run_command(config='.stestr.conf', repo_type='file',
blacklist_file=None, whitelist_file=None, black_regex=None,
no_discover=False, random=False, combine=False, filters=None,
pretty_out=True, color=False, stdout=sys.stdout,
abbreviate=False):
abbreviate=False, suppress_attachments=False):
"""Function to execute the run command
This function implements the run command. It will run the tests specified
Expand Down Expand Up @@ -275,6 +285,8 @@ def run_command(config='.stestr.conf', repo_type='file',
:param file stdout: The file object to write all output to. By default this
is sys.stdout
:param bool abbreviate: Use abbreviated output if set true
:param bool suppress_attachments: When set true attachments subunit_trace
will not print attachments on successful test execution.
:return return_code: The exit code for the command. 0 for success and > 0
for failures.
Expand Down Expand Up @@ -314,7 +326,8 @@ def run_tests():
repo_type=repo_type,
repo_url=repo_url, run_id=combine_id,
pretty_out=pretty_out,
color=color, stdout=stdout, abbreviate=abbreviate)
color=color, stdout=stdout, abbreviate=abbreviate,
suppress_attachments=suppress_attachments)

if not until_failure:
return run_tests()
Expand Down Expand Up @@ -380,18 +393,12 @@ def run_tests():
whitelist_file=whitelist_file, black_regex=black_regex,
randomize=random, test_path=test_path, top_dir=top_dir)

run_result = _run_tests(cmd, failing,
analyze_isolation,
isolated,
until_failure,
subunit_out=subunit_out,
combine_id=combine_id,
repo_type=repo_type,
repo_url=repo_url,
pretty_out=pretty_out,
color=color,
abbreviate=abbreviate,
stdout=stdout)
run_result = _run_tests(
cmd, failing, analyze_isolation, isolated, until_failure,
subunit_out=subunit_out, combine_id=combine_id,
repo_type=repo_type, repo_url=repo_url,
pretty_out=pretty_out, color=color, abbreviate=abbreviate,
stdout=stdout, suppress_attachments=suppress_attachments)
if run_result > result:
result = run_result
return result
Expand All @@ -405,7 +412,8 @@ def run_tests():
pretty_out=pretty_out,
color=color,
stdout=stdout,
abbreviate=abbreviate)
abbreviate=abbreviate,
suppress_attachments=suppress_attachments)
else:
# Where do we source data about the cause of conflicts.
latest_run = repo.get_latest_run()
Expand Down Expand Up @@ -450,7 +458,7 @@ def run_tests():
def _run_tests(cmd, failing, analyze_isolation, isolated, until_failure,
subunit_out=False, combine_id=None, repo_type='file',
repo_url=None, pretty_out=True, color=False, stdout=sys.stdout,
abbreviate=False):
abbreviate=False, suppress_attachments=False):
"""Run the tests cmd was parameterised with."""
cmd.setUp()
try:
Expand All @@ -466,7 +474,8 @@ def run_tests():
repo_type=repo_type,
repo_url=repo_url, run_id=combine_id,
pretty_out=pretty_out, color=color, stdout=stdout,
abbreviate=abbreviate)
abbreviate=abbreviate,
suppress_attachments=suppress_attachments)

if not until_failure:
return run_tests()
Expand Down
10 changes: 6 additions & 4 deletions stestr/subunit_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def find_test_run_time_diff(test_id, run_time):

def show_outcome(stream, test, print_failures=False, failonly=False,
enable_diff=False, threshold='0', abbreviate=False,
enable_color=False):
enable_color=False, suppress_attachments=False):
global RESULTS
status = test['status']
# TODO(sdague): ask lifeless why on this?
Expand Down Expand Up @@ -205,7 +205,8 @@ def show_outcome(stream, test, print_failures=False, failonly=False,
stream.write(out_string + '] ... ')
color.write('ok', 'green')
stream.write('\n')
print_attachments(stream, test)
if not suppress_attachments:
print_attachments(stream, test)
elif status == 'skip':
if abbreviate:
color.write('S', 'blue')
Expand Down Expand Up @@ -349,7 +350,7 @@ def parse_args():

def trace(stdin, stdout, print_failures=False, failonly=False,
enable_diff=False, abbreviate=False, color=False, post_fails=False,
no_summary=False):
no_summary=False, suppress_attachments=False):
stream = subunit.ByteStreamToStreamResult(
stdin, non_subunit_name='stdout')
outcomes = testtools.StreamToDict(
Expand All @@ -358,7 +359,8 @@ def trace(stdin, stdout, print_failures=False, failonly=False,
failonly=failonly,
enable_diff=enable_diff,
abbreviate=abbreviate,
enable_color=color))
enable_color=color,
suppress_attachments=suppress_attachments))
summary = testtools.StreamSummary()
result = testtools.CopyStreamResult([outcomes, summary])
result = testtools.StreamResultRouter(result)
Expand Down
12 changes: 9 additions & 3 deletions stestr/tests/test_user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@
color: True
abbreviate: True
slowest: True
suppress-attachments: True
failing:
list: True
last:
no-subunit-trace: True
color: True
suppress-attachments: True
load:
force-init: True
subunit-trace: True
color: True
abbreviate: True
suppress-attachments: True
"""

INVALID_YAML_FIELD = """
Expand Down Expand Up @@ -147,17 +150,20 @@ def test_user_config_full_config(self, open_mock):
'no-subunit-trace': True,
'color': True,
'abbreviate': True,
'slowest': True},
'slowest': True,
'suppress-attachments': True},
'failing': {
'list': True},
'last': {
'no-subunit-trace': True,
'color': True},
'color': True,
'suppress-attachments': True},
'load': {
'force-init': True,
'subunit-trace': True,
'color': True,
'abbreviate': True}
'abbreviate': True,
'suppress-attachments': True}
}
self.assertEqual(full_dict, user_conf.config)

Expand Down
3 changes: 3 additions & 0 deletions stestr/user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ def __init__(self, path):
vp.Optional('color'): bool,
vp.Optional('abbreviate'): bool,
vp.Optional('slowest'): bool,
vp.Optional('suppress-attachments'): bool,
},
vp.Optional('failing'): {
vp.Optional('list'): bool,
},
vp.Optional('last'): {
vp.Optional('no-subunit-trace'): bool,
vp.Optional('color'): bool,
vp.Optional('suppress-attachments'): bool,
},
vp.Optional('load'): {
vp.Optional('force-init'): bool,
vp.Optional('subunit-trace'): bool,
vp.Optional('color'): bool,
vp.Optional('abbreviate'): bool,
vp.Optional('suppress-attachments'): bool,
}
})
with open(path, 'r') as fd:
Expand Down

0 comments on commit 4470ba0

Please sign in to comment.