forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
59 lines (43 loc) · 2.15 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import absolute_import
import os
import sys
from hashlib import md5
import pytest
pytest_plugins = ["sentry.utils.pytest"]
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
def pytest_configure(config):
import warnings
# XXX(dramer): Kombu throws a warning due to transaction.commit_manually
# being used
warnings.filterwarnings("error", "", Warning, r"^(?!(|kombu|raven|sentry))")
# if we are running any tests for plugins, we need to make sure we install them first
# (for `py.test --version` or `py.test --help`, there are no files to test)
test_targets = config.getoption("file_or_dir")
if test_targets and any("tests/sentry_plugins" in s for s in test_targets):
install_sentry_plugins()
def install_sentry_plugins():
# Sentry's pytest plugin explicitly doesn't load plugins, so let's load all of them
# and ignore the fact that we're not *just* testing our own
# Note: We could manually register/configure INSTALLED_APPS by traversing our entry points
# or package directories, but this is easier assuming Sentry doesn't change APIs.
# Note: Order of operations matters here.
from sentry.runner.importer import install_plugin_apps
from django.conf import settings
install_plugin_apps("sentry.apps", settings)
from sentry.runner.initializer import register_plugins
register_plugins(settings, raise_on_plugin_load_failure=True)
settings.ASANA_CLIENT_ID = "abc"
settings.ASANA_CLIENT_SECRET = "123"
settings.BITBUCKET_CONSUMER_KEY = "abc"
settings.BITBUCKET_CONSUMER_SECRET = "123"
settings.GITHUB_APP_ID = "abc"
settings.GITHUB_API_SECRET = "123"
settings.GITHUB_APPS_APP_ID = "abc"
settings.GITHUB_APPS_API_SECRET = "123"
# this isn't the real secret
settings.SENTRY_OPTIONS["github.integration-hook-secret"] = "b3002c3e321d4b7880360d397db2ccfd"
def pytest_collection_modifyitems(items):
for item in items:
total_groups = int(os.environ.get("TOTAL_TEST_GROUPS", 1))
group_num = int(md5(item.location[0]).hexdigest(), 16) % total_groups
item.add_marker(getattr(pytest.mark, "group_%s" % group_num))