Skip to content

Instantly share code, notes, and snippets.

@pmalmgren
Last active March 29, 2017 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmalmgren/56746a122eb2a1ed7132c660e4983d65 to your computer and use it in GitHub Desktop.
Save pmalmgren/56746a122eb2a1ed7132c660e4983d65 to your computer and use it in GitHub Desktop.
Splits the output of a pytest file into the format: filename.py 5 failures
import re
import sys
start = re.compile('collected [0-9]+ items')
end = re.compile('=+ FAILURES =+')
fail = re.compile('F')
error = re.compile('E')
def split_failures(file_name):
with open(file_name) as file_handler:
contents = file_handler.read()
start_match = start.search(contents)
end_match = end.search(contents)
return contents[start_match.end():end_match.start()].strip().split('\n')
def count_files(failures):
for failure in failures:
split_failure = failure.split(' ')
num_failures = len(fail.findall(split_failure[1]))
num_errors = len(error.findall(split_failure[1]))
if num_failures > 0 or num_errors > 0:
print "{}\n{} failures {} errors".format(split_failure[0], num_failures, num_errors)
def main():
file_name = sys.argv[1]
count_files(split_failures(file_name))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment