Last active
March 29, 2017 19:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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