[Twisted-Python] slightly silly hack

zooko at zooko.com zooko at zooko.com
Tue Jan 10 01:47:01 EST 2006

Ever wanted to execute your trial tests as though they were commands?  You can
use tab completion in bash, for example:

$ ./amdlib/storage/test/test_storefile.py -s

It's easy!  Give your file executable permission and at the top of the file
type this line: "#!/usr/bin/env python".  At the bottom type: """
if __name__ == "__main__":
    import os, sys
    mods = []
    fullname = os.path.realpath(os.path.abspath(__file__))
    for pathel in sys.path:
        fullnameofpathel = os.path.realpath(os.path.abspath(pathel))
        if fullname.startswith(fullnameofpathel):
            relname = fullname[len(fullnameofpathel):]
            mod = (os.path.splitext(relname)[0]).replace(os.sep, '.').strip('.')

    mods.sort(cmp=lambda x, y: cmp(len(x), len(y)))
    for mod in mods:
        cmdstr = "trial %s %s" % (' '.join(sys.argv[1:]), mod,)
        print cmdstr
        if os.system(cmdstr) == 0:



More information about the Twisted-Python mailing list