1
+ import asyncio
2
+ import os
3
+
1
4
import pytest
5
+ import pyppeteer
2
6
3
7
4
8
@pytest .fixture (params = [True , False ])
@@ -21,3 +25,45 @@ async def test_syntax_error(http_server_client, syntax_error_notebook_url, show_
21
25
else :
22
26
assert 'There was an error when executing cell' in output
23
27
assert 'This should not be executed' not in output
28
+
29
+
30
+ async def test_output_widget_traceback (http_server_client , exception_runtime_notebook_url , show_tracebacks ):
31
+ options = dict (headless = False , devtools = True ) if os .environ .get ('VOILA_TEST_DEBUG_VISUAL' , False ) else {}
32
+ # with headless and gpu enabled, we get slightly different results on the same OS
33
+ # we can enable it if we need to, since we allow for a tolerance
34
+ launcher = pyppeteer .launcher .Launcher (options = options , autoClose = False , args = ['--font-render-hinting=none' , '--disable-gpu' ])
35
+ browser = await launcher .launch ()
36
+ page = await browser .newPage ()
37
+ try :
38
+ await page .goto (http_server_client .get_url (exception_runtime_notebook_url ), waitUntil = 'networkidle2' )
39
+ await page .evaluate ('async () => await VoilaDebug.widgetManagerPromise' )
40
+ await page .evaluate ('async () => await VoilaDebug.waitForAllViews()' )
41
+ await page .evaluate ("document.querySelector('.button2').click()" )
42
+ for i in range (20 ):
43
+ await asyncio .sleep (0.05 )
44
+ output_text = await page .evaluate ("document.querySelector('.output_exception').innerText" )
45
+ if output_text :
46
+ break
47
+ else :
48
+ assert False , f"Never received output"
49
+ if show_tracebacks :
50
+ assert 'this happens after the notebook is executed' in output_text
51
+ else :
52
+ assert 'this happens after the notebook is executed' not in output_text
53
+ except Exception as e : # noqa
54
+ if os .environ .get ('VOILA_TEST_DEBUG_VISUAL' , False ):
55
+ import traceback
56
+ traceback .print_exc ()
57
+ # may want to add --async-test-timeout=60 to pytest arguments
58
+ print ("Waiting for 60 second for visual inspection (hit ctrl-c to break)" )
59
+ import sys
60
+ sys .stdout .flush ()
61
+ sys .stderr .flush ()
62
+ try :
63
+ await asyncio .sleep (60 )
64
+ except : # noqa ignore ctrl-c
65
+ pass
66
+ raise e
67
+ finally :
68
+ await browser .close ()
69
+ await launcher .killChrome ()
0 commit comments