11import concurrent .futures as cf
22import sys
3-
43import pytest
54
65from openfeature import api
109from sentry_sdk .integrations .openfeature import OpenFeatureIntegration
1110
1211
12+ @pytest .fixture
13+ def reset_openfeature (uninstall_integration ):
14+ yield
15+
16+ # Teardown
17+ uninstall_integration (OpenFeatureIntegration .identifier )
18+ api .clear_hooks ()
19+ api .shutdown () # provider clean up
20+
21+
1322@pytest .mark .parametrize (
1423 "use_global_client" ,
1524 (False , True ),
1625)
1726def test_openfeature_integration (
18- sentry_init , use_global_client , capture_events , uninstall_integration
27+ sentry_init , use_global_client , capture_events , reset_openfeature
1928):
2029 flags = {
2130 "hello" : InMemoryFlag ("on" , {"on" : True , "off" : False }),
@@ -24,7 +33,6 @@ def test_openfeature_integration(
2433 api .set_provider (InMemoryProvider (flags ))
2534 client = api .get_client ()
2635
27- uninstall_integration (OpenFeatureIntegration .identifier )
2836 if use_global_client :
2937 sentry_init (integrations = [OpenFeatureIntegration ()])
3038 else :
@@ -48,7 +56,7 @@ def test_openfeature_integration(
4856
4957
5058def test_openfeature_integration_threaded (
51- sentry_init , capture_events , uninstall_integration
59+ sentry_init , capture_events , reset_openfeature
5260):
5361 flags = {
5462 "hello" : InMemoryFlag ("on" , {"on" : True , "off" : False }),
@@ -57,7 +65,6 @@ def test_openfeature_integration_threaded(
5765 api .set_provider (InMemoryProvider (flags ))
5866 client = api .get_client ()
5967
60- uninstall_integration (OpenFeatureIntegration .identifier )
6168 sentry_init (integrations = [OpenFeatureIntegration (client = client )])
6269 events = capture_events ()
6370
@@ -104,7 +111,7 @@ def task(flag):
104111
105112@pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "requires python3.7 or higher" )
106113def test_openfeature_integration_asyncio (
107- sentry_init , capture_events , uninstall_integration
114+ sentry_init , capture_events , reset_openfeature
108115):
109116 """Assert concurrently evaluated flags do not pollute one another."""
110117
@@ -117,7 +124,6 @@ def test_openfeature_integration_asyncio(
117124 api .set_provider (InMemoryProvider (flags ))
118125 client = api .get_client ()
119126
120- uninstall_integration (OpenFeatureIntegration .identifier )
121127 sentry_init (integrations = [OpenFeatureIntegration (client = client )])
122128 events = capture_events ()
123129
@@ -160,3 +166,31 @@ async def runner():
160166 {"flag" : "world" , "result" : False },
161167 ]
162168 }
169+
170+
171+ def test_openfeature_integration_client_isolation (
172+ sentry_init , capture_events , reset_openfeature
173+ ):
174+ """
175+ If the integration is tracking a single client, evaluations from other clients should not be
176+ captured.
177+ """
178+ flags = {
179+ "hello" : InMemoryFlag ("on" , {"on" : True , "off" : False }),
180+ "world" : InMemoryFlag ("off" , {"on" : True , "off" : False }),
181+ }
182+ api .set_provider (InMemoryProvider (flags ))
183+ client = api .get_client ()
184+ sentry_init (integrations = [OpenFeatureIntegration (client = client )])
185+
186+ other_client = api .get_client ()
187+ other_client .get_boolean_value ("hello" , default_value = False )
188+ other_client .get_boolean_value ("world" , default_value = False )
189+ other_client .get_boolean_value ("other" , default_value = True )
190+
191+ events = capture_events ()
192+ sentry_sdk .set_tag ("apple" , "0" )
193+ sentry_sdk .capture_exception (Exception ("something wrong!" ))
194+
195+ assert len (events ) == 1
196+ assert events [0 ]["contexts" ]["flags" ] == {"values" : []}
0 commit comments