Skip to content

Commit

Permalink
Properly handle sys.exit() as sys.exit(0). Fixes #489
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 12, 2020
1 parent e573ea7 commit a7282e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def get_variable_presentation(setting, default):
self.api.set_show_return_values(py_db, self._options.show_return_value)

if not self._options.break_system_exit_zero:
ignore_system_exit_codes = [0]
ignore_system_exit_codes = [0, None]
if self._options.django_debug:
ignore_system_exit_codes += [3]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys


def main():
print('TEST SUCEEDED!')
sys.exit()


main() # call_main_line
14 changes: 8 additions & 6 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,17 +1011,19 @@ def test_case_sys_exit_unhandled_exception(case_setup):


@pytest.mark.parametrize('break_on_system_exit_zero', [True, False])
def test_case_sys_exit_0_unhandled_exception(case_setup, break_on_system_exit_zero):
@pytest.mark.parametrize('target', ['_debugger_case_sysexit_0.py', '_debugger_case_sysexit_none.py'])
def test_case_sys_exit_0_unhandled_exception(case_setup, break_on_system_exit_zero, target):

with case_setup.test_file('_debugger_case_sysexit_0.py', EXPECTED_RETURNCODE=0) as writer:
with case_setup.test_file(target, EXPECTED_RETURNCODE=0) as writer:
json_facade = JsonFacade(writer)
json_facade.write_launch(
debugOptions=['BreakOnSystemExitZero'] if break_on_system_exit_zero else [],
)
kwargs = {}
if break_on_system_exit_zero:
kwargs = {'breakOnSystemExitZero': True}
json_facade.write_launch(**kwargs)
json_facade.write_set_exception_breakpoints(['uncaught'])
json_facade.write_make_initial_run()

break_line = writer.get_line_index_with_content('sys.exit(0)')
break_line = writer.get_line_index_with_content('sys.exit(')
if break_on_system_exit_zero:
json_facade.wait_for_thread_stopped(
reason='exception', line=break_line)
Expand Down

0 comments on commit a7282e9

Please sign in to comment.