conftest.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from __future__ import absolute_import
  2. import os
  3. import sys
  4. from hashlib import md5
  5. import six
  6. import pytest
  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. # always install plugins for the tests
  15. install_sentry_plugins()
  16. # add custom test markers
  17. config.addinivalue_line(
  18. "markers",
  19. "sentry_store_integration: mark test as using the sentry store endpoint and therefore using legacy code",
  20. )
  21. config.addinivalue_line(
  22. "markers", "relay_store_integration: mark test as using the relay store endpoint"
  23. )
  24. config.addinivalue_line("markers", "obsolete: mark test as obsolete and soon to be removed")
  25. def install_sentry_plugins():
  26. # Sentry's pytest plugin explicitly doesn't load plugins, so let's load all of them
  27. # and ignore the fact that we're not *just* testing our own
  28. # Note: We could manually register/configure INSTALLED_APPS by traversing our entry points
  29. # or package directories, but this is easier assuming Sentry doesn't change APIs.
  30. # Note: Order of operations matters here.
  31. from sentry.runner.importer import install_plugin_apps
  32. from django.conf import settings
  33. install_plugin_apps("sentry.apps", settings)
  34. from sentry.runner.initializer import register_plugins
  35. register_plugins(settings, raise_on_plugin_load_failure=True)
  36. settings.ASANA_CLIENT_ID = "abc"
  37. settings.ASANA_CLIENT_SECRET = "123"
  38. settings.BITBUCKET_CONSUMER_KEY = "abc"
  39. settings.BITBUCKET_CONSUMER_SECRET = "123"
  40. settings.GITHUB_APP_ID = "abc"
  41. settings.GITHUB_API_SECRET = "123"
  42. # this isn't the real secret
  43. settings.SENTRY_OPTIONS["github.integration-hook-secret"] = "b3002c3e321d4b7880360d397db2ccfd"
  44. def pytest_collection_modifyitems(config, items):
  45. for item in items:
  46. total_groups = int(os.environ.get("TOTAL_TEST_GROUPS", 1))
  47. # TODO(joshuarli): six 1.12.0 adds ensure_binary: six.ensure_binary(item.location[0])
  48. group_num = (
  49. int(md5(six.text_type(item.location[0]).encode("utf-8")).hexdigest(), 16) % total_groups
  50. )
  51. marker = "group_%s" % group_num
  52. config.addinivalue_line("markers", marker)
  53. item.add_marker(getattr(pytest.mark, marker))