Trying to guess at what runtests actually wants in terms of command line
tests is pretty hard. Any invalid value just gives you an ugly traceback.
So add a helper --list option so the user can easily figure out what the
code wants *exactly*.
+ if options.list_tests:
+ testdir = os.path.dirname(sys.argv[0])
+ for mydir in getTestDirs(basedir):
+ testsubdir = os.path.basename(mydir)
+ for name in getTestNames(mydir):
+ print("%s/%s/%s.py" % (testdir, testsubdir, name))
+ sys.exit(0)
+
if len(args) > 1:
suite.addTests(getTestFromCommandLine(args[1:], basedir))
return TextTestRunner(verbosity=2).run(suite)
- # the os.walk help mentions relative paths as being quirky
- # I was tired of adding dirs to the list, so now we add __test__
- # to each dir we want tested.
- for root, dirs, files in os.walk(basedir):
- if svn_dirname in dirs:
- dirs.remove(svn_dirname)
- try:
- root = _unicode_decode(root,
- encoding=_encodings['fs'], errors='strict')
- except UnicodeDecodeError:
- continue
-
- if TEST_FILE in files:
- testDirs.append(root)
-
- testDirs.sort()
- for mydir in testDirs:
+ for mydir in getTestDirs(basedir):
suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
return TextTestRunner(verbosity=2).run(suite)
+def getTestDirs(base_path):
+ TEST_FILE = b'__test__'
+ svn_dirname = b'.svn'
+ testDirs = []
+
+ # the os.walk help mentions relative paths as being quirky
+ # I was tired of adding dirs to the list, so now we add __test__
+ # to each dir we want tested.
+ for root, dirs, files in os.walk(base_path):
+ if svn_dirname in dirs:
+ dirs.remove(svn_dirname)
+ try:
+ root = _unicode_decode(root,
+ encoding=_encodings['fs'], errors='strict')
+ except UnicodeDecodeError:
+ continue
+
+ if TEST_FILE in files:
+ testDirs.append(root)
+
+ testDirs.sort()
+ return testDirs
+
def getTestNames(path):
files = os.listdir(path)
files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]
--
1.7.6.1