Skip to content

Commit 916efdc

Browse files
committed
adjustments for the test for the debugger, making test more robust for testing and not relying on a specific string to be present as a comment
1 parent 950888c commit 916efdc

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

dash/_callback.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@
4040
from ._callback_context import context_value
4141

4242

43-
async def _async_invoke_callback(func, *args, **kwargs):
43+
async def _async_invoke_callback(
44+
func, *args, **kwargs
45+
): # used to mark the frame for the debugger
4446
# Check if the function is a coroutine function
4547
if asyncio.iscoroutinefunction(func):
46-
return await func(*args, **kwargs)
48+
return await func(*args, **kwargs) # %% callback invoked %%
4749
else:
4850
# If the function is not a coroutine, call it directly
49-
return func(*args, **kwargs)
51+
return func(*args, **kwargs) # %% callback invoked %%
5052

5153

52-
def _invoke_callback(func, *args, **kwargs):
53-
return func(*args, **kwargs)
54+
def _invoke_callback(func, *args, **kwargs): # used to mark the frame for the debugger
55+
return func(*args, **kwargs) # %% callback invoked %%
5456

5557

5658
class NoUpdate:

dash/dash.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,34 @@ def _get_traceback(secret, error: Exception):
150150
def _get_skip(error):
151151
from dash._callback import ( # pylint: disable=import-outside-toplevel
152152
_invoke_callback,
153+
_async_invoke_callback,
153154
)
154155

155156
tb = error.__traceback__
156157
skip = 1
157158
while tb.tb_next is not None:
158159
skip += 1
159160
tb = tb.tb_next
160-
if tb.tb_frame.f_code is _invoke_callback.__code__:
161+
if tb.tb_frame.f_code in [
162+
_invoke_callback.__code__,
163+
_async_invoke_callback.__code__,
164+
]:
161165
return skip
162166

163167
return skip
164168

165169
def _do_skip(error):
166170
from dash._callback import ( # pylint: disable=import-outside-toplevel
167171
_invoke_callback,
172+
_async_invoke_callback,
168173
)
169174

170175
tb = error.__traceback__
171176
while tb.tb_next is not None:
172-
if tb.tb_frame.f_code is _invoke_callback.__code__:
177+
if tb.tb_frame.f_code in [
178+
_invoke_callback.__code__,
179+
_async_invoke_callback.__code__,
180+
]:
173181
return tb.tb_next
174182
tb = tb.tb_next
175183
return error.__traceback__

tests/integration/devtools/test_devtools_error_handling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def test_dveh001_python_errors(dash_duo):
7272
assert "Special 2 clicks exception" in error0
7373
assert "in bad_sub" not in error0
7474
# dash and flask part of the traceback not included
75-
assert "%% callback invoked %%" not in error0
75+
assert "dash.py" not in error0
7676
assert "self.wsgi_app" not in error0
7777

7878
error1 = get_error_html(dash_duo, 1)
7979
assert "in update_output" in error1
8080
assert "in bad_sub" in error1
8181
assert "ZeroDivisionError" in error1
82-
assert "%% callback invoked %%" not in error1
82+
assert "dash.py" not in error1
8383
assert "self.wsgi_app" not in error1
8484

8585

@@ -108,14 +108,14 @@ def test_dveh006_long_python_errors(dash_duo):
108108
assert "in bad_sub" not in error0
109109
# dash and flask part of the traceback ARE included
110110
# since we set dev_tools_prune_errors=False
111-
assert "%% callback invoked %%" in error0
111+
assert "dash.py" in error0
112112
assert "self.wsgi_app" in error0
113113

114114
error1 = get_error_html(dash_duo, 1)
115115
assert "in update_output" in error1
116116
assert "in bad_sub" in error1
117117
assert "ZeroDivisionError" in error1
118-
assert "%% callback invoked %%" in error1
118+
assert "dash.py" in error1
119119
assert "self.wsgi_app" in error1
120120

121121

0 commit comments

Comments
 (0)