Skip to content

Commit fea761c

Browse files
committed
Use importorskip
1 parent 2cea37b commit fea761c

File tree

3 files changed

+57
-58
lines changed

3 files changed

+57
-58
lines changed

tests/integrations/featureflags/test_featureflags.py

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# import asyncio
21
import concurrent.futures as cf
32

43
import sentry_sdk
@@ -7,8 +6,7 @@
76
add_feature_flag,
87
)
98

10-
# import pytest
11-
# import sys
9+
import pytest
1210

1311

1412
def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
@@ -81,56 +79,53 @@ def task(flag_key):
8179
}
8280

8381

84-
#
85-
#
86-
# @pytest.mark.skipif(
87-
# sys.version_info < (3, 7), reason="Test requires Python 3.7 or higher"
88-
# )
89-
# def test_featureflags_integration_asyncio(
90-
# sentry_init, capture_events, uninstall_integration
91-
# ):
92-
# uninstall_integration(FeatureFlagsIntegration.identifier)
93-
# sentry_init(integrations=[FeatureFlagsIntegration()])
94-
# events = capture_events()
95-
#
96-
# # Capture an eval before we split isolation scopes.
97-
# add_feature_flag("hello", False)
98-
#
99-
# async def task(flag_key):
100-
# # Creates a new isolation scope for the thread.
101-
# # This means the evaluations in each task are captured separately.
102-
# with sentry_sdk.isolation_scope():
103-
# add_feature_flag(flag_key, False)
104-
# # use a tag to identify to identify events later on
105-
# sentry_sdk.set_tag("task_id", flag_key)
106-
# sentry_sdk.capture_exception(Exception("something wrong!"))
107-
#
108-
# async def runner():
109-
# return asyncio.gather(task("world"), task("other"))
110-
#
111-
# asyncio.run(runner())
112-
#
113-
# # Capture error in original scope
114-
# sentry_sdk.set_tag("task_id", "0")
115-
# sentry_sdk.capture_exception(Exception("something wrong!"))
116-
#
117-
# assert len(events) == 3
118-
# events.sort(key=lambda e: e["tags"]["task_id"])
119-
#
120-
# assert events[0]["contexts"]["flags"] == {
121-
# "values": [
122-
# {"flag": "hello", "result": False},
123-
# ]
124-
# }
125-
# assert events[1]["contexts"]["flags"] == {
126-
# "values": [
127-
# {"flag": "hello", "result": False},
128-
# {"flag": "other", "result": False},
129-
# ]
130-
# }
131-
# assert events[2]["contexts"]["flags"] == {
132-
# "values": [
133-
# {"flag": "hello", "result": False},
134-
# {"flag": "world", "result": False},
135-
# ]
136-
# }
82+
def test_featureflags_integration_asyncio(
83+
sentry_init, capture_events, uninstall_integration
84+
):
85+
asyncio = pytest.importorskip("asyncio") # Only available in Python 3.7+.
86+
87+
uninstall_integration(FeatureFlagsIntegration.identifier)
88+
sentry_init(integrations=[FeatureFlagsIntegration()])
89+
events = capture_events()
90+
91+
# Capture an eval before we split isolation scopes.
92+
add_feature_flag("hello", False)
93+
94+
async def task(flag_key):
95+
# Creates a new isolation scope for the thread.
96+
# This means the evaluations in each task are captured separately.
97+
with sentry_sdk.isolation_scope():
98+
add_feature_flag(flag_key, False)
99+
# use a tag to identify to identify events later on
100+
sentry_sdk.set_tag("task_id", flag_key)
101+
sentry_sdk.capture_exception(Exception("something wrong!"))
102+
103+
async def runner():
104+
return asyncio.gather(task("world"), task("other"))
105+
106+
asyncio.run(runner())
107+
108+
# Capture error in original scope
109+
sentry_sdk.set_tag("task_id", "0")
110+
sentry_sdk.capture_exception(Exception("something wrong!"))
111+
112+
assert len(events) == 3
113+
events.sort(key=lambda e: e["tags"]["task_id"])
114+
115+
assert events[0]["contexts"]["flags"] == {
116+
"values": [
117+
{"flag": "hello", "result": False},
118+
]
119+
}
120+
assert events[1]["contexts"]["flags"] == {
121+
"values": [
122+
{"flag": "hello", "result": False},
123+
{"flag": "other", "result": False},
124+
]
125+
}
126+
assert events[2]["contexts"]["flags"] == {
127+
"values": [
128+
{"flag": "hello", "result": False},
129+
{"flag": "world", "result": False},
130+
]
131+
}

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import concurrent.futures as cf
32

43
import ldclient
@@ -114,6 +113,9 @@ def test_launchdarkly_integration_asyncio(
114113
sentry_init, capture_events, uninstall_integration
115114
):
116115
"""Assert concurrently evaluated flags do not pollute one another."""
116+
117+
asyncio = pytest.importorskip("asyncio") # Only available in Python 3.7+.
118+
117119
td = TestData.data_source()
118120
client = LDClient(config=Config("sdk-key", update_processor_class=td))
119121
context = Context.create("user1")

tests/integrations/openfeature/test_openfeature.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import asyncio
21
import concurrent.futures as cf
32
import sentry_sdk
43

54
from openfeature import api
65
from openfeature.provider.in_memory_provider import InMemoryFlag, InMemoryProvider
76
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
7+
import pytest
88

99

1010
def test_openfeature_integration(sentry_init, capture_events, uninstall_integration):
@@ -95,6 +95,8 @@ def test_openfeature_integration_asyncio(
9595
):
9696
"""Assert concurrently evaluated flags do not pollute one another."""
9797

98+
asyncio = pytest.importorskip("asyncio") # Only available in Python 3.7+.
99+
98100
uninstall_integration(OpenFeatureIntegration.identifier)
99101
sentry_init(integrations=[OpenFeatureIntegration()])
100102
events = capture_events()

0 commit comments

Comments
 (0)