Skip to content

Commit 374d84c

Browse files
authored
Revert generator logic and fix isolation scope creation (#44)
The main yield has to be outside the `use_isolation_scope` blocks because otherwise stuff in the test logic will use the pytest Client and report errors and exceptions too causing a regression.
1 parent 144b71a commit 374d84c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

pytest_sentry/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ def _resolve_scope_marker_value_uncached(marker_value):
4141

4242
if isinstance(marker_value, str):
4343
# If a DSN string is provided, create a new client and use that
44-
scope = sentry_sdk.get_isolation_scope()
44+
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
4545
scope.set_client(Client(marker_value))
4646
return scope
4747

4848
if isinstance(marker_value, dict):
4949
# If a dict is provided, create a new client using the dict as Client options
50-
scope = sentry_sdk.get_isolation_scope()
50+
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
5151
scope.set_client(Client(**marker_value))
5252
return scope
5353

5454
if isinstance(marker_value, Client):
5555
# If a Client instance is provided, use that
56-
scope = sentry_sdk.get_isolation_scope()
56+
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
5757
scope.set_client(marker_value)
5858
return scope
5959

6060
if isinstance(marker_value, sentry_sdk.Scope):
6161
# If a Scope instance is provided, use the client from it
62-
scope = sentry_sdk.get_isolation_scope()
62+
scope = sentry_sdk.Scope(ty=ScopeType.ISOLATION)
6363
scope.set_client(marker_value.client)
6464
return marker_value
6565

pytest_sentry/hooks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ def _with_isolation_scope(wrapped, instance, args, kwargs):
3636
else:
3737
with sentry_sdk.use_isolation_scope(isolation_scope):
3838
gen = wrapped(*args, **kwargs)
39-
yield from gen
39+
40+
while True:
41+
try:
42+
with sentry_sdk.use_isolation_scope(isolation_scope):
43+
chunk = next(gen)
44+
45+
y = yield chunk
46+
47+
with sentry_sdk.use_isolation_scope(isolation_scope):
48+
gen.send(y)
49+
50+
except StopIteration:
51+
break
4052

4153
def inner(f):
4254
return pytest.hookimpl(hookwrapper=True, **kwargs)(_with_isolation_scope(f))

tests/test_scope.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ def test_basic():
2525
_assert_right_scopes()
2626

2727

28-
def test_correct_span():
29-
# Ensure that we are within a root span (started by the pytest_runtest_call hook)
30-
assert sentry_sdk.get_current_scope().span is not None
31-
32-
3328
class TestSimpleClass(object):
3429
def setup_method(self):
3530
_assert_right_scopes()

0 commit comments

Comments
 (0)