conftest.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from __future__ import absolute_import
  2. import os
  3. import sys
  4. from hashlib import md5
  5. import pytest
  6. pytest_plugins = ["sentry.utils.pytest"]
  7. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
  8. def pytest_configure(config):
  9. import warnings
  10. # XXX(dramer): Kombu throws a warning due to transaction.commit_manually
  11. # being used
  12. warnings.filterwarnings("error", "", Warning, r"^(?!(|kombu|raven|sentry))")
  13. # always install plugins for the tests
  14. install_sentry_plugins()
  15. def install_sentry_plugins():
  16. # Sentry's pytest plugin explicitly doesn't load plugins, so let's load all of them
  17. # and ignore the fact that we're not *just* testing our own
  18. # Note: We could manually register/configure INSTALLED_APPS by traversing our entry points
  19. # or package directories, but this is easier assuming Sentry doesn't change APIs.
  20. # Note: Order of operations matters here.
  21. from sentry.runner.importer import install_plugin_apps
  22. from django.conf import settings
  23. install_plugin_apps("sentry.apps", settings)
  24. from sentry.runner.initializer import register_plugins
  25. register_plugins(settings, raise_on_plugin_load_failure=True)
  26. settings.ASANA_CLIENT_ID = "abc"
  27. settings.ASANA_CLIENT_SECRET = "123"
  28. settings.BITBUCKET_CONSUMER_KEY = "abc"
  29. settings.BITBUCKET_CONSUMER_SECRET = "123"
  30. settings.GITHUB_APP_ID = "abc"
  31. settings.GITHUB_API_SECRET = "123"
  32. # this isn't the real secret
  33. settings.SENTRY_OPTIONS["github.integration-hook-secret"] = "b3002c3e321d4b7880360d397db2ccfd"
  34. def pytest_collection_modifyitems(config, items):
  35. for item in items:
  36. total_groups = int(os.environ.get("TOTAL_TEST_GROUPS", 1))
  37. group_num = int(md5(item.location[0]).hexdigest(), 16) % total_groups
  38. marker = "group_%s" % group_num
  39. config.addinivalue_line("markers", marker)
  40. item.add_marker(getattr(pytest.mark, marker))