MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / test_unhandled_exceptions_basic

Function test_unhandled_exceptions_basic

tests_python/test_debugger.py:1577–1642  ·  view source on GitHub ↗
(case_setup)

Source from the content-addressed store, hash-verified

1575
1576@pytest.mark.skipif(IS_JYTHON, reason="Failing on Jython -- needs to be investigated).")
1577def test_unhandled_exceptions_basic(case_setup):
1578 def check_test_suceeded_msg(writer, stdout, stderr):
1579 # Don't call super (we have an unhandled exception in the stack trace).
1580 return "TEST SUCEEDED" in "".join(stdout) and "TEST SUCEEDED" in "".join(stderr)
1581
1582 def additional_output_checks(writer, stdout, stderr):
1583 if "raise Exception" not in stderr:
1584 raise AssertionError("Expected test to have an unhandled exception.\nstdout:\n%s\n\nstderr:\n%s" % (stdout, stderr))
1585
1586 with case_setup.test_file(
1587 "_debugger_case_unhandled_exceptions.py",
1588 check_test_suceeded_msg=check_test_suceeded_msg,
1589 additional_output_checks=additional_output_checks,
1590 EXPECTED_RETURNCODE=1,
1591 ) as writer:
1592 writer.write_add_exception_breakpoint_with_policy("Exception", "0", "1", "0")
1593 writer.write_make_initial_run()
1594
1595 def check(hit, exc_type, exc_desc):
1596 writer.write_get_current_exception(hit.thread_id)
1597 msg = writer.wait_for_message(
1598 accept_message=lambda msg: exc_type in msg and 'exc_type="' in msg and 'exc_desc="' in msg, unquote_msg=False
1599 )
1600 assert unquote(msg.thread["exc_desc"]) == exc_desc
1601 assert unquote(msg.thread["exc_type"]) in (
1602 "<type 'exceptions.%s'>" % (exc_type,), # py2
1603 "<class '%s'>" % (exc_type,), # py3
1604 )
1605 if len(msg.thread.frame) == 0:
1606 assert unquote(unquote(msg.thread.frame["file"])).endswith("_debugger_case_unhandled_exceptions.py")
1607 else:
1608 assert unquote(unquote(msg.thread.frame[0]["file"])).endswith("_debugger_case_unhandled_exceptions.py")
1609 writer.write_run_thread(hit.thread_id)
1610
1611 # Will stop in 2 background threads
1612 hit0 = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION)
1613 thread_id1 = hit0.thread_id
1614
1615 hit1 = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION)
1616 thread_id2 = hit1.thread_id
1617
1618 if hit0.name == "thread_func2":
1619 check(hit0, "ValueError", "in thread 2")
1620 check(hit1, "Exception", "in thread 1")
1621 else:
1622 check(hit0, "Exception", "in thread 1")
1623 check(hit1, "ValueError", "in thread 2")
1624
1625 writer.write_run_thread(thread_id1)
1626 writer.write_run_thread(thread_id2)
1627
1628 # Will stop in main thread
1629 hit = writer.wait_for_breakpoint_hit(REASON_UNCAUGHT_EXCEPTION)
1630 assert hit.name == "<module>"
1631 thread_id3 = hit.thread_id
1632
1633 # Requesting the stack in an unhandled exception should provide the stack of the exception,
1634 # not the current location of the program.

Callers

nothing calls this directly

Calls 9

test_fileMethod · 0.80
write_run_threadMethod · 0.80
wait_for_messageMethod · 0.80
checkFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected