|
18 | 18 | Hub,
|
19 | 19 | )
|
20 | 20 | from sentry_sdk._compat import reraise
|
21 |
| -from sentry_sdk.integrations import _AUTO_ENABLING_INTEGRATIONS |
| 21 | +from sentry_sdk.integrations import ( |
| 22 | + _AUTO_ENABLING_INTEGRATIONS, |
| 23 | + Integration, |
| 24 | + setup_integrations, |
| 25 | +) |
22 | 26 | from sentry_sdk.integrations.logging import LoggingIntegration
|
| 27 | +from sentry_sdk.integrations.redis import RedisIntegration |
23 | 28 | from sentry_sdk.scope import ( # noqa: F401
|
24 | 29 | add_global_event_processor,
|
25 | 30 | global_event_processors,
|
|
28 | 33 | from sentry_sdk.tracing_utils import has_tracing_enabled
|
29 | 34 |
|
30 | 35 |
|
| 36 | +def _redis_installed(): # type: () -> bool |
| 37 | + """ |
| 38 | + Determines whether Redis is installed. |
| 39 | + """ |
| 40 | + try: |
| 41 | + import redis # noqa: F401 |
| 42 | + except ImportError: |
| 43 | + return False |
| 44 | + |
| 45 | + return True |
| 46 | + |
| 47 | + |
| 48 | +class NoOpIntegration(Integration): |
| 49 | + """ |
| 50 | + A simple no-op integration for testing purposes. |
| 51 | + """ |
| 52 | + |
| 53 | + identifier = "noop" |
| 54 | + |
| 55 | + @staticmethod |
| 56 | + def setup_once(): # type: () -> None |
| 57 | + pass |
| 58 | + |
| 59 | + def __eq__(self, __value): # type: (object) -> bool |
| 60 | + """ |
| 61 | + All instances of NoOpIntegration should be considered equal to each other. |
| 62 | + """ |
| 63 | + return type(__value) == type(self) |
| 64 | + |
| 65 | + |
31 | 66 | def test_processors(sentry_init, capture_events):
|
32 | 67 | sentry_init()
|
33 | 68 | events = capture_events()
|
@@ -59,8 +94,8 @@ def test_auto_enabling_integrations_catches_import_error(sentry_init, caplog):
|
59 | 94 | sentry_init(auto_enabling_integrations=True, debug=True)
|
60 | 95 |
|
61 | 96 | for import_string in _AUTO_ENABLING_INTEGRATIONS:
|
62 |
| - # Ignore redis in the test case, because it is installed as a |
63 |
| - # dependency for running tests, and therefore always enabled. |
| 97 | + # Ignore redis in the test case, because it does not raise a DidNotEnable |
| 98 | + # exception on import; rather, it raises the exception upon enabling. |
64 | 99 | if _AUTO_ENABLING_INTEGRATIONS[redis_index] == import_string:
|
65 | 100 | continue
|
66 | 101 |
|
@@ -686,3 +721,18 @@ def test_functions_to_trace_with_class(sentry_init, capture_events):
|
686 | 721 | assert len(event["spans"]) == 2
|
687 | 722 | assert event["spans"][0]["description"] == "tests.test_basics.WorldGreeter.greet"
|
688 | 723 | assert event["spans"][1]["description"] == "tests.test_basics.WorldGreeter.greet"
|
| 724 | + |
| 725 | + |
| 726 | +@pytest.mark.skipif(_redis_installed(), reason="skipping because redis is installed") |
| 727 | +def test_redis_disabled_when_not_installed(sentry_init): |
| 728 | + sentry_init() |
| 729 | + |
| 730 | + assert Hub.current.get_integration(RedisIntegration) is None |
| 731 | + |
| 732 | + |
| 733 | +def test_multiple_setup_integrations_calls(): |
| 734 | + first_call_return = setup_integrations([NoOpIntegration()], with_defaults=False) |
| 735 | + assert first_call_return == {NoOpIntegration.identifier: NoOpIntegration()} |
| 736 | + |
| 737 | + second_call_return = setup_integrations([NoOpIntegration()], with_defaults=False) |
| 738 | + assert second_call_return == {NoOpIntegration.identifier: NoOpIntegration()} |
0 commit comments