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.

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import shutil
  3. import warnings
  4. import django
  5. def pytest_addoption(parser):
  6. parser.addoption("--sqlite", action="store_true")
  7. parser.addoption("--deprecation", choices=["strict", "log", "none"], default="log")
  8. def pytest_configure(config):
  9. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
  10. deprecation = config.getoption("deprecation")
  11. if deprecation == "strict":
  12. warnings.simplefilter("error", DeprecationWarning)
  13. warnings.simplefilter("error", PendingDeprecationWarning)
  14. warnings.simplefilter("error", RuntimeWarning)
  15. if deprecation == "log":
  16. warnings.simplefilter("always", DeprecationWarning)
  17. warnings.simplefilter("always", PendingDeprecationWarning)
  18. warnings.simplefilter("always", RuntimeWarning)
  19. elif deprecation == "none":
  20. # Deprecation warnings are ignored by default
  21. pass
  22. if config.getoption("sqlite"):
  23. os.environ["DATABASE_ENGINE"] = "django.db.backends.sqlite3"
  24. os.environ["DATABASE_NAME"] = ":memory:"
  25. django.setup()
  26. # pylint: disable=unused-argument
  27. def pytest_unconfigure(config):
  28. # remove tests/public/media folder
  29. from django.conf import settings
  30. shutil.rmtree(settings.MEDIA_ROOT, ignore_errors=True)