Add a Nosetests plugin that lets me specify a test order within a directory.

This commit is contained in:
Jim Paris 2013-01-05 18:00:59 -05:00
parent 3d212e7592
commit b7688844fa
3 changed files with 66 additions and 2 deletions

View File

@ -9,10 +9,10 @@ lint:
pylint -f parseable nilmdb
test:
nosetests
python runtests.py
profile:
nosetests --with-profile
python runtests.py --with-profile
clean::
find . -name '*pyc' | xargs rm -f

46
runtests.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/python
import nose
import os
import sys
import glob
from collections import OrderedDict
class JimOrderPlugin(nose.plugins.Plugin):
"""When searching for tests and encountering a directory that
contains a 'test.order' file, run tests listed in that file, in the
order that they're listed. Globs are OK in that file and duplicates
are removed."""
name = 'jimorder'
score = 10000
def prepareTestLoader(self, loader):
def wrap(func):
def wrapper(name, *args, **kwargs):
addr = nose.selector.TestAddress(
name, workingDir=loader.workingDir)
try:
order = os.path.join(addr.filename, "test.order")
except:
order = None
if order and os.path.exists(order):
files = []
for line in open(order):
line = line.strip()
if not line:
continue
fn = os.path.join(addr.filename, line.strip())
files.extend(sorted(glob.glob(fn)) or [fn])
files = list(OrderedDict.fromkeys(files))
tests = [ wrapper(fn, *args, **kwargs) for fn in files ]
return loader.suiteClass(tests)
return func(name, *args, **kwargs)
return wrapper
loader.loadTestsFromName = wrap(loader.loadTestsFromName)
return loader
# Use setup.cfg for most of the test configuration. Adding
# --with-jimorder here means that a normal "nosetests" run will
# still work, it just won't support test.order.
nose.main(addplugins = [ JimOrderPlugin() ],
argv = sys.argv + ["--with-jimorder"])

18
tests/test.order Normal file
View File

@ -0,0 +1,18 @@
test_printf.py
test_lrucache.py
test_mustclose.py
test_serializer.py
test_iteratorizer.py
test_timestamper.py
test_layout.py
test_rbtree.py
test_interval.py
test_bulkdata.py
test_nilmdb.py
test_client.py
test_cmdline.py
test_*.py