File tree 2 files changed +17
-18
lines changed
tests/integrations/launchdarkly
2 files changed +17
-18
lines changed Original file line number Diff line number Diff line change 20
20
21
21
class LaunchDarklyIntegration (Integration ):
22
22
identifier = "launchdarkly"
23
+ _ld_client = None # type: LDClient | None
23
24
24
25
def __init__ (self , ld_client = None ):
25
26
# type: (LDClient | None) -> None
26
27
"""
27
28
:param client: An initialized LDClient instance. If a client is not provided, this
28
29
integration will attempt to use the shared global instance.
29
30
"""
31
+ self .__class__ ._ld_client = ld_client
32
+
33
+ @staticmethod
34
+ def setup_once ():
35
+ # type: () -> None
30
36
try :
31
- client = ld_client or ldclient .get ()
37
+ client = LaunchDarklyIntegration . _ld_client or ldclient .get ()
32
38
except Exception as exc :
33
39
raise DidNotEnable ("Error getting LaunchDarkly client. " + repr (exc ))
34
40
35
- if not client .is_initialized ():
36
- raise DidNotEnable ("LaunchDarkly client is not initialized." )
37
-
38
41
# Register the flag collection hook with the LD client.
39
42
client .add_hook (LaunchDarklyHook ())
40
43
41
- @staticmethod
42
- def setup_once ():
43
- # type: () -> None
44
44
scope = sentry_sdk .get_current_scope ()
45
45
scope .add_error_processor (flag_error_processor )
46
46
Original file line number Diff line number Diff line change @@ -168,22 +168,21 @@ async def runner():
168
168
}
169
169
170
170
171
- def test_launchdarkly_integration_did_not_enable (monkeypatch ):
172
- # Client is not passed in and set_config wasn't called.
173
- # TODO: Bad practice to access internals like this. We can skip this test, or remove this
174
- # case entirely (force user to pass in a client instance).
171
+ def test_launchdarkly_integration_did_not_enable (sentry_init , uninstall_integration ):
172
+ """
173
+ Setup should fail when using global client and ldclient.set_config wasn't called.
174
+
175
+ We're accessing ldclient internals to set up this test, so it might break if launchdarkly's
176
+ implementation changes.
177
+ """
178
+
175
179
ldclient ._reset_client ()
176
180
try :
177
181
ldclient .__lock .lock ()
178
182
ldclient .__config = None
179
183
finally :
180
184
ldclient .__lock .unlock ()
181
185
186
+ uninstall_integration (LaunchDarklyIntegration .identifier )
182
187
with pytest .raises (DidNotEnable ):
183
- LaunchDarklyIntegration ()
184
-
185
- # Client not initialized.
186
- client = LDClient (config = Config ("sdk-key" ))
187
- monkeypatch .setattr (client , "is_initialized" , lambda : False )
188
- with pytest .raises (DidNotEnable ):
189
- LaunchDarklyIntegration (ld_client = client )
188
+ sentry_init (integrations = [LaunchDarklyIntegration ()])
You can’t perform that action at this time.
0 commit comments