Skip to content

Instantly share code, notes, and snippets.

@fschulze
Created October 31, 2016 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fschulze/f884807bdbb30b2ecb7dfce7516f3a46 to your computer and use it in GitHub Desktop.
Save fschulze/f884807bdbb30b2ecb7dfce7516f3a46 to your computer and use it in GitHub Desktop.
Filters failed tests from zope.testrunner output to be suitable for ```-t $(failed_tests)```
#!/usr/bin/env python
import subprocess
def get_tests_from_paste_buffer():
return subprocess.check_output('pbpaste')
def run():
raw_tests = get_tests_from_paste_buffer()
tests = []
for test in raw_tests.splitlines():
test = test.strip()
if not test:
continue
if test.endswith('.txt'):
test = test.split('/')[-1]
tests.append(test)
elif ' (' in test:
test = test.replace(' (', '\\s.*').replace(')', '')
tests.append(test)
print '|'.join(tests)
if __name__ == '__main__':
run()
@witsch
Copy link

witsch commented Nov 2, 2016

nice catch regarding the additional module spec…

my pimped shell alias version is now:

alias failed_tests="pbpaste | egrep '^ *(test.*\)|/.*\.txt)' | cut -d\) -f1 | sed -e 's, (,##s.*,' -e 's,.*/,,' | xargs | tr ' #' '\|\\' | xargs -J% bin/alltests -v -v -v -t '%'"

:)

@witsch
Copy link

witsch commented Nov 2, 2016

so the diff from before was…

diff --git a/.bash_aliases b/.bash_aliases
index d34bb11..e935612 100644
--- a/.bash_aliases
+++ b/.bash_aliases
@@ -44,7 +44,7 @@
 alias failed_open="pbpaste | grep ', in test' | sed -e 's/^[^\"]*\"//' -e 's/\", line /:/' -e 's/,.*//' -e 's,.*/buildout/,,' | xargs subl"
-alias failed_tests="pbpaste | egrep '^ *(test.*\(|/.*\.txt)' | cut -d\( -f1 | sed 's,.*/,,' | xargs | tr ' ' '\|' | xargs -J% bin/alltests -v -v -v -t '%'"
+alias failed_tests="pbpaste | egrep '^ *(test.*\)|/.*\.txt)' | cut -d\) -f1 | sed -e 's, (,##s.*,' -e 's,.*/,,' | xargs | tr ' #' '\|\\' | xargs -J% bin/alltests -v -v -v 
 alias find="gfind"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment