您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

64 行
1.4 KiB

  1. """
  2. Run tests from modules. Sets up database connection, modules path and session before running test
  3. Usage: from shell, run
  4. python tests.py [test modules]
  5. Options:
  6. test modules: list of modules separated by space
  7. if no modules are specified, it will run all "tests.py" files from all modules
  8. """
  9. import sys, os
  10. import unittest
  11. # webnotes path
  12. sys.path.append('lib/py')
  13. # modules path
  14. import webnotes
  15. import webnotes.defs
  16. if webnotes.defs.__dict__.get('modules_path'):
  17. sys.path.append(webnotes.defs.modules_path)
  18. def get_tests():
  19. """
  20. Returns list of test modules identified by "test*.py"
  21. """
  22. ret = []
  23. for walk_tuple in os.walk(webnotes.defs.modules_path):
  24. for test_file in filter(lambda x: x.startswith('test') and x.endswith('.py'), walk_tuple[2]):
  25. dir_path = os.path.relpath(walk_tuple[0], webnotes.defs.modules_path)
  26. if dir_path=='.':
  27. ret.append(test_file[:-3])
  28. else:
  29. ret.append(dir_path.replace('/', '.') + '.' + test_file[:-3])
  30. return ret
  31. def setup():
  32. """
  33. Sets up connection and session
  34. """
  35. from webnotes.db import Database
  36. webnotes.conn = Database()
  37. webnotes.session = {'user':'Administrator'}
  38. if __name__=='__main__':
  39. setup()
  40. if len(sys.argv) > 1:
  41. tests_list = sys.argv[1:]
  42. # for unittest.main
  43. sys.argv = sys.argv[:1]
  44. else:
  45. tests_list = get_tests()
  46. for tests in tests_list:
  47. exec 'from %s import *' % str(tests)
  48. unittest.main()