File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ import warnings
2+
13from typing import TYPE_CHECKING
24
35import sentry_sdk
911
1012
1113class _InitGuard :
14+ _CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE = (
15+ "Using the return value of sentry_sdk.init as a context manager "
16+ "and manually calling the __enter__ and __exit__ methods on the "
17+ "return value are deprecated. We are no longer maintaining this "
18+ "functionality, and we will remove it in the next major release."
19+ )
20+
1221 def __init__ (self , client ):
1322 # type: (sentry_sdk.Client) -> None
1423 self ._client = client
1524
1625 def __enter__ (self ):
1726 # type: () -> _InitGuard
27+ warnings .warn (
28+ self ._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE ,
29+ stacklevel = 2 ,
30+ category = DeprecationWarning ,
31+ )
32+
1833 return self
1934
2035 def __exit__ (self , exc_type , exc_value , tb ):
2136 # type: (Any, Any, Any) -> None
37+ warnings .warn (
38+ self ._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE ,
39+ stacklevel = 2 ,
40+ category = DeprecationWarning ,
41+ )
42+
2243 c = self ._client
2344 if c is not None :
2445 c .close ()
Original file line number Diff line number Diff line change 11import pytest
22from unittest import mock
33
4+ import sentry_sdk
45from sentry_sdk import (
56 capture_exception ,
67 continue_trace ,
@@ -195,3 +196,19 @@ def test_push_scope_deprecation():
195196 with pytest .warns (DeprecationWarning ):
196197 with push_scope ():
197198 ...
199+
200+
201+ def test_init_context_manager_deprecation ():
202+ with pytest .warns (DeprecationWarning ):
203+ with sentry_sdk .init ():
204+ ...
205+
206+
207+ def test_init_enter_deprecation ():
208+ with pytest .warns (DeprecationWarning ):
209+ sentry_sdk .init ().__enter__ ()
210+
211+
212+ def test_init_exit_deprecation ():
213+ with pytest .warns (DeprecationWarning ):
214+ sentry_sdk .init ().__exit__ (None , None , None )
You can’t perform that action at this time.
0 commit comments