Last active
August 29, 2015 13:57
-
-
Save carymrobbins/9676067 to your computer and use it in GitHub Desktop.
Simple helper to parse test runner results into a list of test names.
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 | |
| def get_failed_tests(s): | |
| """Pass in the string output from your test runner to get the test names | |
| in the format path.to.test.module:TestClass.test_name | |
| """ | |
| regex = re.compile(r'(FAIL|ERROR): (\w+) \(([^\)]+)\)') | |
| return [ | |
| '{0[0]}.{0[1]}'.format(*((':'.join(path.rsplit('.', 1)), name) | |
| for _, name, path in [match.groups()])) | |
| for match in map(regex.match, s.splitlines()) if match | |
| ] | |
| if __name__ == '__main__': | |
| import sys | |
| if sys.stdin.isatty(): | |
| print(get_failed_tests(sys.argv[1])) | |
| else: | |
| print(get_failed_tests(sys.stdin.read())) | |
| # Example Usage: | |
| test_data = """ | |
| ...E..F.... | |
| ====================================================================== | |
| ERROR: test_blah (oh.em.gee.MyTest) | |
| ---------------------------------------------------------------------- | |
| Traceback (most recent call last): | |
| File "gee.py", line 123, in diggity | |
| raise ValueError('foo') | |
| ValueError: foo | |
| ====================================================================== | |
| FAIL: test_huh (yo.dog.diggity.SuperTest) | |
| ---------------------------------------------------------------------- | |
| Traceback (most recent call last): | |
| File "diggity.py", line 544, in diggity | |
| raise YoMama | |
| YoMama: Is so ugly that people go as her for Halloween. | |
| ---------------------------------------------------------------------- | |
| Ran 2 tests in 102.148s | |
| FAILED (errors=1, failures=1) | |
| Process finished with exit code 1 | |
| """ | |
| assert get_failed_tests(test_data) == [ | |
| 'oh.em.gee:MyTest.test_blah', | |
| 'yo.dog.diggity:SuperTest.test_huh' | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment