You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.8 KiB

  1. #!/usr/bin/python
  2. import nose
  3. import os
  4. import sys
  5. import glob
  6. from collections import OrderedDict
  7. class JimOrderPlugin(nose.plugins.Plugin):
  8. """When searching for tests and encountering a directory that
  9. contains a 'test.order' file, run tests listed in that file, in the
  10. order that they're listed. Globs are OK in that file and duplicates
  11. are removed."""
  12. name = 'jimorder'
  13. score = 10000
  14. def prepareTestLoader(self, loader):
  15. def wrap(func):
  16. def wrapper(name, *args, **kwargs):
  17. addr = nose.selector.TestAddress(
  18. name, workingDir=loader.workingDir)
  19. try:
  20. order = os.path.join(addr.filename, "test.order")
  21. except:
  22. order = None
  23. if order and os.path.exists(order):
  24. files = []
  25. for line in open(order):
  26. line = line.split('#')[0].strip()
  27. if not line:
  28. continue
  29. fn = os.path.join(addr.filename, line.strip())
  30. files.extend(sorted(glob.glob(fn)) or [fn])
  31. files = list(OrderedDict.fromkeys(files))
  32. tests = [ wrapper(fn, *args, **kwargs) for fn in files ]
  33. return loader.suiteClass(tests)
  34. return func(name, *args, **kwargs)
  35. return wrapper
  36. loader.loadTestsFromName = wrap(loader.loadTestsFromName)
  37. return loader
  38. # Use setup.cfg for most of the test configuration. Adding
  39. # --with-jimorder here means that a normal "nosetests" run will
  40. # still work, it just won't support test.order.
  41. nose.main(addplugins = [ JimOrderPlugin() ],
  42. argv = sys.argv + ["--with-jimorder"])