Skip to content

Commit 0538bce

Browse files
committed
ref uninstall_integration fixture
1 parent da54e49 commit 0538bce

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

tests/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import jsonschema
1212

13+
1314
try:
1415
import gevent
1516
except ImportError:
@@ -27,6 +28,7 @@
2728
_DEFAULT_INTEGRATIONS,
2829
_installed_integrations,
2930
_processed_integrations,
31+
Integration,
3032
)
3133
from sentry_sdk.profiler import teardown_profiler
3234
from sentry_sdk.profiler.continuous_profiler import teardown_continuous_profiler
@@ -185,10 +187,17 @@ def reset_integrations():
185187

186188

187189
@pytest.fixture
188-
def reset_integration():
189-
"""Use to force the next call to sentry_init to re-install/setup an integration."""
190+
def uninstall_integration():
191+
"""
192+
Forces the next call to sentry_init to re-install an integration and call `setup_once`.
193+
No effect if the integration is not installed.
194+
"""
190195

191-
def inner(identifier):
196+
def inner(name_or_cls):
197+
if isinstance(name_or_cls, str):
198+
identifier = name_or_cls
199+
else:
200+
identifier = name_or_cls.identifier
192201
_processed_integrations.discard(identifier)
193202
_installed_integrations.discard(identifier)
194203

tests/integrations/featureflags/test_featureflags.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
)
1111

1212

13-
def test_featureflags_integration(sentry_init, capture_events, reset_integration):
14-
reset_integration(FeatureFlagsIntegration.identifier)
13+
def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
14+
uninstall_integration(FeatureFlagsIntegration.identifier)
1515
sentry_init(integrations=[FeatureFlagsIntegration()])
1616

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

3333

3434
def test_featureflags_integration_threaded(
35-
sentry_init, capture_events, reset_integration
35+
sentry_init, capture_events, uninstall_integration
3636
):
37-
reset_integration(FeatureFlagsIntegration.identifier)
37+
uninstall_integration(FeatureFlagsIntegration.identifier)
3838
sentry_init(integrations=[FeatureFlagsIntegration()])
3939
events = capture_events()
4040

@@ -82,11 +82,11 @@ def task(flag_key):
8282

8383
@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
8484
def test_featureflags_integration_asyncio(
85-
sentry_init, capture_events, reset_integration
85+
sentry_init, capture_events, uninstall_integration
8686
):
8787
asyncio = pytest.importorskip("asyncio")
8888

89-
reset_integration(FeatureFlagsIntegration.identifier)
89+
uninstall_integration(FeatureFlagsIntegration.identifier)
9090
sentry_init(integrations=[FeatureFlagsIntegration()])
9191
events = capture_events()
9292

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
(False, True),
2020
)
2121
def test_launchdarkly_integration(
22-
sentry_init, use_global_client, capture_events, reset_integration
22+
sentry_init, use_global_client, capture_events, uninstall_integration
2323
):
2424
td = TestData.data_source()
2525
config = Config("sdk-key", update_processor_class=td)
2626

27-
reset_integration(LaunchDarklyIntegration.identifier)
27+
uninstall_integration(LaunchDarklyIntegration.identifier)
2828
if use_global_client:
2929
ldclient.set_config(config)
3030
sentry_init(integrations=[LaunchDarklyIntegration()])
@@ -56,13 +56,13 @@ def test_launchdarkly_integration(
5656

5757

5858
def test_launchdarkly_integration_threaded(
59-
sentry_init, capture_events, reset_integration
59+
sentry_init, capture_events, uninstall_integration
6060
):
6161
td = TestData.data_source()
6262
client = LDClient(config=Config("sdk-key", update_processor_class=td))
6363
context = Context.create("user1")
6464

65-
reset_integration(LaunchDarklyIntegration.identifier)
65+
uninstall_integration(LaunchDarklyIntegration.identifier)
6666
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
6767
events = capture_events()
6868

@@ -111,7 +111,7 @@ def task(flag_key):
111111

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

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

124-
reset_integration(LaunchDarklyIntegration.identifier)
124+
uninstall_integration(LaunchDarklyIntegration.identifier)
125125
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
126126
events = capture_events()
127127

tests/integrations/openfeature/test_openfeature.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
1111

1212

13-
def test_openfeature_integration(sentry_init, capture_events, reset_integration):
14-
reset_integration(OpenFeatureIntegration.identifier)
13+
def test_openfeature_integration(sentry_init, capture_events, uninstall_integration):
14+
uninstall_integration(OpenFeatureIntegration.identifier)
1515
sentry_init(integrations=[OpenFeatureIntegration()])
1616

1717
flags = {
@@ -39,9 +39,9 @@ def test_openfeature_integration(sentry_init, capture_events, reset_integration)
3939

4040

4141
def test_openfeature_integration_threaded(
42-
sentry_init, capture_events, reset_integration
42+
sentry_init, capture_events, uninstall_integration
4343
):
44-
reset_integration(OpenFeatureIntegration.identifier)
44+
uninstall_integration(OpenFeatureIntegration.identifier)
4545
sentry_init(integrations=[OpenFeatureIntegration()])
4646
events = capture_events()
4747

@@ -95,13 +95,13 @@ def task(flag):
9595

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

102102
asyncio = pytest.importorskip("asyncio")
103103

104-
reset_integration(OpenFeatureIntegration.identifier)
104+
uninstall_integration(OpenFeatureIntegration.identifier)
105105
sentry_init(integrations=[OpenFeatureIntegration()])
106106
events = capture_events()
107107

tests/integrations/unleash/test_unleash.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
13-
def test_is_enabled(sentry_init, capture_events, reset_integration):
13+
def test_is_enabled(sentry_init, capture_events, uninstall_integration):
1414
client = MockUnleashClient()
15-
reset_integration(UnleashIntegration.identifier)
15+
uninstall_integration(UnleashIntegration)
1616
sentry_init(integrations=[UnleashIntegration()])
1717

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

3434

3535
@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
36-
def test_get_variant(sentry_init, capture_events, reset_integration):
36+
def test_get_variant(sentry_init, capture_events, uninstall_integration):
3737
client = MockUnleashClient()
38-
reset_integration(UnleashIntegration.identifier)
38+
uninstall_integration(UnleashIntegration)
3939
sentry_init(integrations=[UnleashIntegration()])
4040

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

5959

6060
@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
61-
def test_wraps_original(sentry_init, reset_integration):
62-
reset_integration(UnleashIntegration.identifier)
61+
def test_wraps_original(sentry_init, uninstall_integration):
62+
uninstall_integration(UnleashIntegration)
6363

6464
with patch(
6565
"sentry_sdk.integrations.unleash.UnleashClient.is_enabled"
@@ -88,8 +88,8 @@ def test_wraps_original(sentry_init, reset_integration):
8888

8989

9090
@patch("sentry_sdk.integrations.unleash.UnleashClient", MockUnleashClient)
91-
def test_wrapper_attributes(sentry_init, reset_integration):
92-
reset_integration(UnleashIntegration.identifier)
91+
def test_wrapper_attributes(sentry_init, uninstall_integration):
92+
uninstall_integration(UnleashIntegration)
9393
sentry_init(integrations=[UnleashIntegration()])
9494

9595
client = MockUnleashClient()

0 commit comments

Comments
 (0)