Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running with ipython 8 results in crash

See original GitHub issue


Usint ipytest with latest ipython 8.0.1 results in program crash with ModuleNotFoundError.


Simple test notebook


import ipytest

def test_fail():
    assert False

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 - 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/ in <module>
     26         # IPython 3
---> 27         from IPython.kernel import KernelManager
     28         from IPython.nbformat import NotebookNode

ModuleNotFoundError: No module named 'IPython.kernel'



It seems that following replacements all-over the code solve the issue:

  1. from IPython.nbformat import… -> from nbformat import
  2. from IPython.kernel import… -> jupyter_client import

Probably have to be embedded in some try:... except:... for backwards compatibility.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

ralfschulzecommented, Jan 25, 2022

Are you sure about the == 0 line? In my tests the run() method always give None and there does not seem to be a return statement in run()

What 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 an exit 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 put assert 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!

chmpcommented, Feb 2, 2022

@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

  1. Use ipytest.autoconfig(raise_on_error=True)
  2. Use assert == 0

It would be cool, if you could proide feedback, whether the changes work for your use case.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found