Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

tests.py 1.4 KiB

há 14 anos
há 14 anos
há 14 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
  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()