mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -05:00
Make sure that tests fail in case there is an unhandled Python error (#1456)
Before this PR, the following test passed:
def test_pyscript_hello(self):
self.pyscript_run(
"""
<script type="py">
raise Exception("hello")
</script>
""")
What happens is that we intercept the Python exception and display a nice banner on the DOM, but the test itself passes. This is error prone: if we have Python exceptions on the page, the test should fail by default, and we should have a way to silence it in case those exceptions are expected.
This PR treats Python errors as we treat JS errors: unhandled exceptions cause the test to fail, but you can silence them by calling self.check_py_errors(), exactly as you can call self.check_js_errors().
This commit is contained in:
@@ -183,6 +183,8 @@ class TestPyRepl(PyScriptTest):
|
||||
tb_lines = err_pre.inner_text().splitlines()
|
||||
assert tb_lines[0] == "Traceback (most recent call last):"
|
||||
assert tb_lines[-1] == "Exception: this is an error"
|
||||
#
|
||||
self.check_py_errors("this is an error")
|
||||
|
||||
@skip_worker("FIXME: display()")
|
||||
def test_multiple_repls(self):
|
||||
@@ -228,6 +230,8 @@ class TestPyRepl(PyScriptTest):
|
||||
out_div = self.page.wait_for_selector("#py-internal-0-repl-output")
|
||||
assert "hello world" not in out_div.inner_text()
|
||||
assert "ZeroDivisionError" in out_div.inner_text()
|
||||
#
|
||||
self.check_py_errors("ZeroDivisionError")
|
||||
|
||||
@skip_worker("FIXME: js.document")
|
||||
def test_hide_previous_error_after_successful_run(self):
|
||||
@@ -253,6 +257,8 @@ class TestPyRepl(PyScriptTest):
|
||||
# test runner can be too fast, the line below should wait for output to change
|
||||
out_div = self.page.wait_for_selector("#py-internal-0-repl-output")
|
||||
assert out_div.inner_text() == "hello"
|
||||
#
|
||||
self.check_py_errors("this is an error")
|
||||
|
||||
def test_output_attribute_does_not_exist(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user