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.

runtests.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Re-run failing tests (requires pytest-cache)
  16. $ ./runtests.py ... --lf
  17. Drop into pdb when a test fails
  18. $ ./runtests.py ... --pdb
  19. """
  20. import os
  21. import multiprocessing
  22. import sys
  23. import logging
  24. import warnings
  25. import pytest
  26. from django.utils.six.moves import map
  27. # No logging
  28. logging.disable(logging.CRITICAL)
  29. if __name__ == '__main__':
  30. args = sys.argv[1:]
  31. verbosity = 1
  32. if not args:
  33. # If run with no args, try and run the testsuite as fast as possible.
  34. # That means across all cores and with no high-falutin' plugins.
  35. try:
  36. cpu_count = int(multiprocessing.cpu_count())
  37. except ValueError:
  38. cpu_count = 1
  39. args = [
  40. '--capture=no', '--nomigrations', '-n=%d' % cpu_count,
  41. 'tests'
  42. ]
  43. else:
  44. # Some args/options specified. Check to see if any nose options have
  45. # been 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. # Default options:
  49. # --exitfirst Abort on first error/failure
  50. # --capture=no Don't capture STDOUT
  51. args.extend(['--capture=no', '--nomigrations', '--exitfirst'])
  52. else:
  53. args = [arg for arg in args if not arg.startswith('-')]
  54. with warnings.catch_warnings():
  55. # The warnings module in default configuration will never cause tests
  56. # to fail, as it never raises an exception. We alter that behaviour by
  57. # turning DeprecationWarnings into exceptions, but exclude warnings
  58. # triggered by third-party libs. Note: The context manager is not thread
  59. # safe. Behaviour with multiple threads is undefined.
  60. warnings.filterwarnings('error', category=DeprecationWarning)
  61. warnings.filterwarnings('error', category=RuntimeWarning)
  62. libs = r'(sorl\.thumbnail.*|bs4.*|webtest.*)'
  63. warnings.filterwarnings(
  64. 'ignore', r'.*', DeprecationWarning, libs)
  65. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tests.settings')
  66. pytest.main(args)