2
0

runtests.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. import argparse
  3. import os
  4. import shutil
  5. import sys
  6. import warnings
  7. from django.core.management import execute_from_command_line
  8. os.environ['DJANGO_SETTINGS_MODULE'] = 'wagtail.tests.settings'
  9. def make_parser():
  10. parser = argparse.ArgumentParser()
  11. parser.add_argument('--deprecation', choices=['all', 'pending', 'imminent', 'none'], default='imminent')
  12. parser.add_argument('--postgres', action='store_true')
  13. parser.add_argument('--elasticsearch5', action='store_true')
  14. parser.add_argument('--elasticsearch6', action='store_true')
  15. parser.add_argument('--elasticsearch7', action='store_true')
  16. parser.add_argument('--emailuser', action='store_true')
  17. parser.add_argument('--disabletimezone', action='store_true')
  18. parser.add_argument('--bench', action='store_true')
  19. return parser
  20. def parse_args(args=None):
  21. return make_parser().parse_known_args(args)
  22. def runtests():
  23. args, rest = parse_args()
  24. only_wagtail = r'^wagtail(\.|$)'
  25. if args.deprecation == 'all':
  26. # Show all deprecation warnings from all packages
  27. warnings.simplefilter('default', DeprecationWarning)
  28. warnings.simplefilter('default', PendingDeprecationWarning)
  29. elif args.deprecation == 'pending':
  30. # Show all deprecation warnings from wagtail
  31. warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail)
  32. warnings.filterwarnings('default', category=PendingDeprecationWarning, module=only_wagtail)
  33. elif args.deprecation == 'imminent':
  34. # Show only imminent deprecation warnings from wagtail
  35. warnings.filterwarnings('default', category=DeprecationWarning, module=only_wagtail)
  36. elif args.deprecation == 'none':
  37. # Deprecation warnings are ignored by default
  38. pass
  39. if args.postgres:
  40. os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql'
  41. if args.elasticsearch5:
  42. os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
  43. os.environ.setdefault('ELASTICSEARCH_VERSION', '5')
  44. elif args.elasticsearch6:
  45. os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
  46. os.environ.setdefault('ELASTICSEARCH_VERSION', '6')
  47. elif args.elasticsearch7:
  48. os.environ.setdefault('ELASTICSEARCH_URL', 'http://localhost:9200')
  49. os.environ.setdefault('ELASTICSEARCH_VERSION', '7')
  50. elif 'ELASTICSEARCH_URL' in os.environ:
  51. # forcibly delete the ELASTICSEARCH_URL setting to skip those tests
  52. del os.environ['ELASTICSEARCH_URL']
  53. if args.emailuser:
  54. os.environ['USE_EMAIL_USER_MODEL'] = '1'
  55. if args.disabletimezone:
  56. os.environ['DISABLE_TIMEZONE'] = '1'
  57. if args.bench:
  58. benchmarks = [
  59. 'wagtail.admin.tests.benches',
  60. ]
  61. argv = [sys.argv[0], 'test', '-v2'] + benchmarks + rest
  62. else:
  63. argv = [sys.argv[0], 'test'] + rest
  64. try:
  65. execute_from_command_line(argv)
  66. finally:
  67. from wagtail.tests.settings import MEDIA_ROOT, STATIC_ROOT
  68. shutil.rmtree(STATIC_ROOT, ignore_errors=True)
  69. shutil.rmtree(MEDIA_ROOT, ignore_errors=True)
  70. if __name__ == '__main__':
  71. runtests()