Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _capture_output(args, capfd):
"""
Calls chartpress given provided arguments and captures the output during the
call.
"""
# clear cache of in memory cached functions
# this allows us to better mimic the chartpress CLI behavior
chartpress.image_needs_building.cache_clear()
chartpress.image_needs_pushing.cache_clear()
chartpress.latest_tag_or_mod_commit.cache_clear()
# first flush past captured output, then run chartpress, and finally read
# and save all output that came of it
_, _ = capfd.readouterr()
chartpress.main(args)
out, err = capfd.readouterr()
# since the output was captured, print it back out again for debugging
# purposes if a test fails for example
header = f'--- chartpress {" ".join(args)} ---'
footer = "-" * len(header)
print()
print(header)
print(out)
print(footer)
return out