| 380 | "exception, exval", [(EngineError, 1), (InvalidPythonProcess, 2)] |
| 381 | ) |
| 382 | def test_process_remote_error(exception, exval, capsys): |
| 383 | # GIVEN |
| 384 | |
| 385 | argv = ["pystack", "remote", "32"] |
| 386 | |
| 387 | # WHEN |
| 388 | |
| 389 | with patch( |
| 390 | "pystack.__main__.get_process_threads" |
| 391 | ) as get_process_threads_mock, patch( |
| 392 | "pystack.__main__.print_thread" |
| 393 | ) as print_thread_mock, patch( |
| 394 | "sys.argv", argv |
| 395 | ), patch( |
| 396 | "pathlib.Path.exists", return_value=True |
| 397 | ): |
| 398 | get_process_threads_mock.side_effect = exception("Oh no!") |
| 399 | with pytest.raises(SystemExit) as excinfo: |
| 400 | main() |
| 401 | assert excinfo.value.code == exval |
| 402 | |
| 403 | # THEN |
| 404 | |
| 405 | get_process_threads_mock.assert_called_once() |
| 406 | print_thread_mock.assert_not_called() |
| 407 | capture = capsys.readouterr() |
| 408 | assert "Oh no!" in capture.err |
| 409 | |
| 410 | |
| 411 | def test_process_core_default_without_executable(): |