conftest.py 2.1 KB

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