Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

runtests.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env python
  2. """
  3. Custom test runner
  4. If args or options, we run the testsuite as quickly as possible.
  5. If args but no options, we default to using the spec plugin and aborting on
  6. first error/failure.
  7. If options, we ignore defaults and pass options onto Nose.
  8. Examples:
  9. Run all tests (as fast as possible)
  10. $ ./runtests.py
  11. Run all unit tests (using spec output)
  12. $ ./runtests.py tests/unit
  13. Run all checkout unit tests (using spec output)
  14. $ ./runtests.py tests/unit/checkout
  15. Run all tests relating to shipping
  16. $ ./runtests.py --attr=shipping
  17. Re-run failing tests (needs to be run twice to first build the index)
  18. $ ./runtests.py ... --failed
  19. Drop into pdb when a test fails
  20. $ ./runtests.py ... --pdb-failures
  21. """
  22. import sys
  23. import logging
  24. from tests.config import configure
  25. logging.disable(logging.CRITICAL)
  26. def run_tests(*test_args):
  27. from django_nose import NoseTestSuiteRunner
  28. test_runner = NoseTestSuiteRunner()
  29. if not test_args:
  30. test_args = ['tests']
  31. num_failures = test_runner.run_tests(test_args)
  32. if num_failures:
  33. sys.exit(num_failures)
  34. if __name__ == '__main__':
  35. args = sys.argv[1:]
  36. if not args:
  37. import multiprocessing
  38. try:
  39. num_cores = multiprocessing.cpu_count()
  40. except NotImplementedError:
  41. num_cores = 4
  42. args = ['-s', '-x', '--processes=%s' % num_cores]
  43. else:
  44. # Some args specified. Check to see if any nose options have been
  45. # specified. If they have, then don't set any
  46. has_options = any(map(lambda x: x.startswith('--'), args))
  47. if not has_options:
  48. args.extend(['-s', '-x', '--with-specplugin'])
  49. else:
  50. # Remove options as nose will pick these up from sys.argv
  51. args = [arg for arg in args if not arg.startswith('-')]
  52. configure()
  53. run_tests(*args)