Skip to content

Commit

Permalink
ref uninstall_integration fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Dec 23, 2024
1 parent da54e49 commit 0538bce
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
15 changes: 12 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest
import jsonschema


try:
import gevent
except ImportError:
Expand All @@ -27,6 +28,7 @@
_DEFAULT_INTEGRATIONS,
_installed_integrations,
_processed_integrations,
Integration,
)
from sentry_sdk.profiler import teardown_profiler
from sentry_sdk.profiler.continuous_profiler import teardown_continuous_profiler
Expand Down Expand Up @@ -185,10 +187,17 @@ def reset_integrations():


@pytest.fixture
def reset_integration():
"""Use to force the next call to sentry_init to re-install/setup an integration."""
def uninstall_integration():
"""
Forces the next call to sentry_init to re-install an integration and call `setup_once`.
No effect if the integration is not installed.
"""

def inner(identifier):
def inner(name_or_cls):
if isinstance(name_or_cls, str):
identifier = name_or_cls
else:
identifier = name_or_cls.identifier
_processed_integrations.discard(identifier)
_installed_integrations.discard(identifier)

Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/featureflags/test_featureflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)


def test_featureflags_integration(sentry_init, capture_events, reset_integration):
reset_integration(FeatureFlagsIntegration.identifier)
def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
uninstall_integration(FeatureFlagsIntegration.identifier)
sentry_init(integrations=[FeatureFlagsIntegration()])

add_feature_flag("hello", False)
Expand All @@ -32,9 +32,9 @@ def test_featureflags_integration(sentry_init, capture_events, reset_integration


def test_featureflags_integration_threaded(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
reset_integration(FeatureFlagsIntegration.identifier)
uninstall_integration(FeatureFlagsIntegration.identifier)
sentry_init(integrations=[FeatureFlagsIntegration()])
events = capture_events()

Expand Down Expand Up @@ -82,11 +82,11 @@ def task(flag_key):

@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_featureflags_integration_asyncio(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
asyncio = pytest.importorskip("asyncio")

reset_integration(FeatureFlagsIntegration.identifier)
uninstall_integration(FeatureFlagsIntegration.identifier)
sentry_init(integrations=[FeatureFlagsIntegration()])
events = capture_events()

Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/launchdarkly/test_launchdarkly.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
(False, True),
)
def test_launchdarkly_integration(
sentry_init, use_global_client, capture_events, reset_integration
sentry_init, use_global_client, capture_events, uninstall_integration
):
td = TestData.data_source()
config = Config("sdk-key", update_processor_class=td)

reset_integration(LaunchDarklyIntegration.identifier)
uninstall_integration(LaunchDarklyIntegration.identifier)
if use_global_client:
ldclient.set_config(config)
sentry_init(integrations=[LaunchDarklyIntegration()])
Expand Down Expand Up @@ -56,13 +56,13 @@ def test_launchdarkly_integration(


def test_launchdarkly_integration_threaded(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
td = TestData.data_source()
client = LDClient(config=Config("sdk-key", update_processor_class=td))
context = Context.create("user1")

reset_integration(LaunchDarklyIntegration.identifier)
uninstall_integration(LaunchDarklyIntegration.identifier)
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
events = capture_events()

Expand Down Expand Up @@ -111,7 +111,7 @@ def task(flag_key):

@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_launchdarkly_integration_asyncio(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
"""Assert concurrently evaluated flags do not pollute one another."""

Expand All @@ -121,7 +121,7 @@ def test_launchdarkly_integration_asyncio(
client = LDClient(config=Config("sdk-key", update_processor_class=td))
context = Context.create("user1")

reset_integration(LaunchDarklyIntegration.identifier)
uninstall_integration(LaunchDarklyIntegration.identifier)
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
events = capture_events()

Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/openfeature/test_openfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration


def test_openfeature_integration(sentry_init, capture_events, reset_integration):
reset_integration(OpenFeatureIntegration.identifier)
def test_openfeature_integration(sentry_init, capture_events, uninstall_integration):
uninstall_integration(OpenFeatureIntegration.identifier)
sentry_init(integrations=[OpenFeatureIntegration()])

flags = {
Expand Down Expand Up @@ -39,9 +39,9 @@ def test_openfeature_integration(sentry_init, capture_events, reset_integration)


def test_openfeature_integration_threaded(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
reset_integration(OpenFeatureIntegration.identifier)
uninstall_integration(OpenFeatureIntegration.identifier)
sentry_init(integrations=[OpenFeatureIntegration()])
events = capture_events()

Expand Down Expand Up @@ -95,13 +95,13 @@ def task(flag):

@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_openfeature_integration_asyncio(
sentry_init, capture_events, reset_integration
sentry_init, capture_events, uninstall_integration
):
"""Assert concurrently evaluated flags do not pollute one another."""

asyncio = pytest.importorskip("asyncio")

reset_integration(OpenFeatureIntegration.identifier)
uninstall_integration(OpenFeatureIntegration.identifier)
sentry_init(integrations=[OpenFeatureIntegration()])
events = capture_events()

Expand Down
16 changes: 8 additions & 8 deletions tests/integrations/unleash/test_unleash.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
def test_is_enabled(sentry_init, capture_events, reset_integration):
def test_is_enabled(sentry_init, capture_events, uninstall_integration):
client = MockUnleashClient()
reset_integration(UnleashIntegration.identifier)
uninstall_integration(UnleashIntegration)
sentry_init(integrations=[UnleashIntegration()])

client.is_enabled("hello")
Expand All @@ -33,9 +33,9 @@ def test_is_enabled(sentry_init, capture_events, reset_integration):


@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
def test_get_variant(sentry_init, capture_events, reset_integration):
def test_get_variant(sentry_init, capture_events, uninstall_integration):
client = MockUnleashClient()
reset_integration(UnleashIntegration.identifier)
uninstall_integration(UnleashIntegration)
sentry_init(integrations=[UnleashIntegration()])

client.get_variant("toggle_feature")
Expand All @@ -58,8 +58,8 @@ def test_get_variant(sentry_init, capture_events, reset_integration):


@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
def test_wraps_original(sentry_init, reset_integration):
reset_integration(UnleashIntegration.identifier)
def test_wraps_original(sentry_init, uninstall_integration):
uninstall_integration(UnleashIntegration)

with patch(
"sentry_sdk.integrations.unleash.UnleashClient.is_enabled"
Expand Down Expand Up @@ -88,8 +88,8 @@ def test_wraps_original(sentry_init, reset_integration):


@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
def test_wrapper_attributes(sentry_init, reset_integration):
reset_integration(UnleashIntegration.identifier)
def test_wrapper_attributes(sentry_init, uninstall_integration):
uninstall_integration(UnleashIntegration)
sentry_init(integrations=[UnleashIntegration()])

client = MockUnleashClient()
Expand Down

0 comments on commit 0538bce

Please sign in to comment.