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.
 
 
 
 

51 lines
1.9 KiB

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