11# coding: utf-8
22import os
33import json
4+ import mock
45import pytest
56import subprocess
67import sys
2223from sentry_sdk .transport import Transport
2324from sentry_sdk ._compat import reraise , text_type , PY2
2425from sentry_sdk .utils import HAS_CHAINED_EXCEPTIONS
26+ from sentry_sdk .utils import logger
2527from sentry_sdk .serializer import MAX_DATABAG_BREADTH
2628from sentry_sdk .consts import DEFAULT_MAX_BREADCRUMBS
2729
@@ -291,8 +293,48 @@ def e(exc):
291293 pytest .raises (EventCapturedError , lambda : e (ValueError ()))
292294
293295
294- def test_with_locals_enabled (sentry_init , capture_events ):
295- sentry_init (with_locals = True )
296+ def test_with_locals_deprecation_enabled (sentry_init ):
297+ with mock .patch .object (logger , "warning" , mock .Mock ()) as fake_warning :
298+ sentry_init (with_locals = True )
299+
300+ client = Hub .current .client
301+ assert "with_locals" not in client .options
302+ assert "include_local_variables" in client .options
303+ assert client .options ["include_local_variables" ]
304+
305+ fake_warning .assert_called_once_with (
306+ "Deprecated: The option 'with_locals' was renamed to 'include_local_variables'. Please use 'include_local_variables'. The option 'with_locals' will be removed in the future."
307+ )
308+
309+
310+ def test_with_locals_deprecation_disabled (sentry_init ):
311+ with mock .patch .object (logger , "warning" , mock .Mock ()) as fake_warning :
312+ sentry_init (with_locals = False )
313+
314+ client = Hub .current .client
315+ assert "with_locals" not in client .options
316+ assert "include_local_variables" in client .options
317+ assert not client .options ["include_local_variables" ]
318+
319+ fake_warning .assert_called_once_with (
320+ "Deprecated: The option 'with_locals' was renamed to 'include_local_variables'. Please use 'include_local_variables'. The option 'with_locals' will be removed in the future."
321+ )
322+
323+
324+ def test_include_local_variables_deprecation (sentry_init ):
325+ with mock .patch .object (logger , "warning" , mock .Mock ()) as fake_warning :
326+ sentry_init (include_local_variables = False )
327+
328+ client = Hub .current .client
329+ assert "with_locals" not in client .options
330+ assert "include_local_variables" in client .options
331+ assert not client .options ["include_local_variables" ]
332+
333+ fake_warning .assert_not_called ()
334+
335+
336+ def test_include_local_variables_enabled (sentry_init , capture_events ):
337+ sentry_init (include_local_variables = True )
296338 events = capture_events ()
297339 try :
298340 1 / 0
@@ -307,8 +349,8 @@ def test_with_locals_enabled(sentry_init, capture_events):
307349 )
308350
309351
310- def test_with_locals_disabled (sentry_init , capture_events ):
311- sentry_init (with_locals = False )
352+ def test_include_local_variables_disabled (sentry_init , capture_events ):
353+ sentry_init (include_local_variables = False )
312354 events = capture_events ()
313355 try :
314356 1 / 0
@@ -372,7 +414,7 @@ def bar():
372414
373415
374416def test_attach_stacktrace_enabled_no_locals (sentry_init , capture_events ):
375- sentry_init (attach_stacktrace = True , with_locals = False )
417+ sentry_init (attach_stacktrace = True , include_local_variables = False )
376418 events = capture_events ()
377419
378420 def foo ():
0 commit comments