runtests.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. def runtests():
  5. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "devproject.test_settings")
  6. try:
  7. from django import setup
  8. from django.core.management import call_command
  9. except ImportError:
  10. # The above import may fail for some other reason. Ensure that the
  11. # issue is really that Django is missing to avoid masking other
  12. # exceptions on Python 2.
  13. try:
  14. import django
  15. except ImportError:
  16. raise ImportError(
  17. "Couldn't import Django. Are you sure it's installed and "
  18. "available on your PYTHONPATH environment variable? Did you "
  19. "forget to activate a virtual environment?"
  20. )
  21. raise
  22. setup()
  23. modules = sys.argv[1:]
  24. if "test" in modules:
  25. modules.remove("test")
  26. exit_code = call_command("test", *modules, verbosity=1, noinput=True)
  27. sys.exit(exit_code)
  28. if __name__ == '__main__':
  29. runtests()