Running with ipython 8 results in crash
See original GitHub issueIssue
Usint ipytest with latest ipython 8.0.1 results in program crash with ModuleNotFoundError
.
Example
Simple test notebook
ipytest_nb.ipynb
import ipytest
ipytest.autoconfig()
def test_fail():
assert False
ipytest.run()
IPython 7.23.1
(venv) rschulze@red: (dev *)~/development/pyshl$ ipython --TerminalIPythonApp.file_to_run=ipytest_nb.ipynb
F [100%]
============================================= FAILURES =============================================
____________________________________________ test_fail _____________________________________________
def test_fail():
> assert False
E assert False
<ipython-input-1-ff73e06d7454>:2: AssertionError
===================================== short test summary info ======================================
FAILED tmp0n4g6iqq.py::test_fail - assert False
1 failed in 0.05s
IPython 8.0.1
(venv) rschulze@red: (dev *)~/development/pyshl$ ipython --TerminalIPythonApp.file_to_run=ipytest_nb.ipynb
ModuleNotFoundError Traceback (most recent call last)
~/development/pyshl/venv/lib/python3.8/site-packages/runipy/notebook_runner.py in <module>
26 # IPython 3
---> 27 from IPython.kernel import KernelManager
28 from IPython.nbformat import NotebookNode
ModuleNotFoundError: No module named 'IPython.kernel'
[…]
Solution
It seems that following replacements all-over the code solve the issue:
from IPython.nbformat import
… ->from nbformat import
…from IPython.kernel import
… ->jupyter_client import
…
Probably have to be embedded in some try:... except:...
for backwards compatibility.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
ipython 8+ python crash on exception · Issue #13598 - GitHub
This in turn results in a dissociation between the counters of Jupyter and those of its history sqlite database. And when you run...
Read more >IPython Crashes when Running Command - Stack Overflow
When I execute a command in IPython, it returns the result of the command but with an error. Later IPython exits.
Read more >Python Numpy Tutorial (with Jupyter and Colab)
We expect that many of you will have some experience with Python and numpy; for the rest of you, this section will serve...
Read more >5.x Series — IPython 8.7.0 documentation
Clear breakpoints before running any script with debugger. (PR #10699) ... Fix a bug in set_next_input leading to a crash of terminal IPython....
Read more >ipython notebook unstable? (ipython kernel keeps crashing)
I'm trying to use the ipython notebook running on my pi as a persistent testing ... But whatever I run results in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are you sure about the
ipytest.run() == 0
line? In my tests therun()
method always giveNone
and there does not seem to be areturn
statement inrun()
https://github.com/chmp/ipytest/blob/b9d8dff02fddafe0f9a1742b76cbac20d406994a/ipytest/_impl.py#L22What I want to achieve is to run automated unit-tests in my notebook when I push it to our CI/CD.
I tried to run the notebook via
ipython --InteractiveShellApp.code_to_run='%run TestNotebook.ipynb
. That works in the sense that all assertions are reported, but ipython does not set anexit code != 0
when assertions fail, so this does not work for CI/CD.Your solution via
pytest --nbval-lax --current-env TestNotebook.ipynb
gives the clear pytest output, but I have to putassert ipytest.exit_code == 0
at the end of each cell, or the tests will always pass. I would prefer to have this checked automatically, but the line is easy enough to add (Just have to remember it 😃, so I will try to use this solution for my problem.Anyhow: Thanks for sharing this package and also for your support!
@ralfschulze you’re right, the return code is not returned. I released
ipytest==0.12.0b1
which offers two options to make sure test failures lead to exceptions (see https://github.com/chmp/ipytest/issues/63):ipytest.autoconfig(raise_on_error=True)
assert ipytest.run() == 0
It would be cool, if you could proide feedback, whether the changes work for your use case.