conftest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import sys
  3. dist_path = os.path.abspath(
  4. os.path.join(os.path.dirname(__file__), "src", "sentry", "static", "sentry", "dist")
  5. )
  6. manifest_path = os.path.join(dist_path, "manifest.json")
  7. pytest_plugins = ["sentry.utils.pytest"]
  8. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
  9. def pytest_configure(config):
  10. import warnings
  11. # XXX(dcramer): Kombu throws a warning due to transaction.commit_manually
  12. # being used
  13. warnings.filterwarnings("error", "", Warning, r"^(?!(|kombu|raven|sentry))")
  14. # Create an empty webpack manifest file - otherwise tests will crash if it does not exist
  15. os.makedirs(dist_path, exist_ok=True)
  16. # Only create manifest if it doesn't exist
  17. # (e.g. acceptance tests will have an actual manifest from webpack)
  18. if os.path.exists(manifest_path):
  19. return
  20. with open(manifest_path, "w+") as fp:
  21. fp.write("{}")
  22. def pytest_unconfigure():
  23. if not os.path.exists(manifest_path):
  24. return
  25. # Clean up manifest file if contents are empty
  26. with open(manifest_path) as f:
  27. if f.read() == "{}":
  28. os.remove(manifest_path)