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

Function test_soft_terminate

tests_python/test_debugger_json.py:6984–7037  ·  view source on GitHub ↗
(case_setup_dap, pyfile, soft_kill)

Source from the content-addressed store, hash-verified

6982
6983@pytest.mark.parametrize("soft_kill", [False, True])
6984def test_soft_terminate(case_setup_dap, pyfile, soft_kill):
6985 if soft_kill and PYDEVD_USE_SYS_MONITORING:
6986 pytest.skip("Right now when using sys.monitoring exceptions are be handled in callbacks.")
6987
6988 @pyfile
6989 def target():
6990 import time
6991
6992 try:
6993 while True:
6994 time.sleep(0.2) # break here
6995 except KeyboardInterrupt:
6996 # i.e.: The test succeeds if a keyboard interrupt is received.
6997 print("TEST SUCEEDED!")
6998 raise
6999
7000 def check_test_suceeded_msg(self, stdout, stderr):
7001 if soft_kill:
7002 return "TEST SUCEEDED" in "".join(stdout)
7003 else:
7004 return "TEST SUCEEDED" not in "".join(stdout)
7005
7006 def additional_output_checks(writer, stdout, stderr):
7007 if soft_kill:
7008 assert "KeyboardInterrupt" in stderr
7009 else:
7010 assert not stderr
7011
7012 with case_setup_dap.test_file(
7013 target,
7014 EXPECTED_RETURNCODE="any",
7015 check_test_suceeded_msg=check_test_suceeded_msg,
7016 additional_output_checks=additional_output_checks,
7017 ) as writer:
7018 json_facade = JsonFacade(writer)
7019 json_facade.write_launch(onTerminate="KeyboardInterrupt" if soft_kill else "kill", justMyCode=False)
7020
7021 break_line = writer.get_line_index_with_content("break here")
7022 json_facade.write_set_breakpoints(break_line)
7023 json_facade.write_make_initial_run()
7024 json_hit = json_facade.wait_for_thread_stopped(line=break_line)
7025
7026 # Interrupting when inside a breakpoint will actually make the
7027 # debugger stop working in that thread (because there's no way
7028 # to keep debugging after an exception exits the tracing).
7029
7030 json_facade.write_terminate()
7031
7032 if soft_kill:
7033 json_facade.wait_for_json_message(
7034 OutputEvent, lambda output_event: "raised from within the callback set" in output_event.body.output
7035 )
7036
7037 writer.finished_ok = True
7038
7039
7040def test_annotate_function_not_treated_as_user_exception(case_setup_dap, pyfile):

Callers

nothing calls this directly

Calls 9

write_launchMethod · 0.95
write_set_breakpointsMethod · 0.95
write_terminateMethod · 0.95
wait_for_json_messageMethod · 0.95
JsonFacadeClass · 0.85
test_fileMethod · 0.80

Tested by

no test coverage detected