-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jupyter-run: avoid traceback for NoSuchKernel (#994)
* jupyter-run: avoid traceback for NoSuchKernel NoSuchKernel used to raise during KernelManager instantiation, but it is now delayed. Access kernel_spec to ensure it's raised where it will be caught. Also removes a redundant warning log immediately before raising, which prevents complete handling of NoSuchError and produces unavoidable duplicate logs. * call wait_for_ready() in runapp ensures kernel is ready before running avoids lost output if iopub isn't connected yet and shutdown kernel when finished, rather than relying on the kernel shutting itself down
- Loading branch information
Showing
4 changed files
with
45 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
from subprocess import run | ||
|
||
|
||
def test_runapp(tmp_path): | ||
test_py = tmp_path / "test.py" | ||
with test_py.open("w") as f: | ||
f.write("print('hello')") | ||
|
||
p = run( | ||
[sys.executable, "-m", "jupyter_client.runapp", str(test_py)], | ||
capture_output=True, | ||
text=True, | ||
check=True, | ||
) | ||
assert p.stdout.strip() == "hello" | ||
|
||
|
||
def test_no_such_kernel(tmp_path): | ||
test_py = tmp_path / "test.py" | ||
with test_py.open("w") as f: | ||
f.write("print('hello')") | ||
kernel_name = "nosuchkernel" | ||
p = run( | ||
[sys.executable, "-m", "jupyter_client.runapp", "--kernel", kernel_name, str(test_py)], | ||
capture_output=True, | ||
text=True, | ||
check=False, | ||
) | ||
assert p.returncode | ||
assert "Could not find kernel" in p.stderr | ||
assert kernel_name in p.stderr | ||
# shouldn't show a traceback | ||
assert "Traceback" not in p.stderr |