Skip to content

Instantly share code, notes, and snippets.

@SergiyKolesnikov
Last active September 24, 2023 14:54
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SergiyKolesnikov/f94d91b947051ab5d2ba1aa30e25f050 to your computer and use it in GitHub Desktop.
Save SergiyKolesnikov/f94d91b947051ab5d2ba1aa30e25f050 to your computer and use it in GitHub Desktop.
Testing and Debugging Jupyter Notebooks
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brianhill
Copy link

Very helpful. I'm also looking around for the goop that would only execute the tests for the class TestNotebook. There might be others discovered from elsewhere that we don't want to execute in the present cell.

@brianhill
Copy link

I'm not claiming the following is minimal or Pythonic, but I can say that it does what I wanted to have happen in my Jupyter notebook:

testSuite = unittest.TestLoader().loadTestsFromName("__main__.TestNotebook")
testRunner = unittest.TextTestRunner(verbosity=2)
testRunner.run(testSuite)

@ycopin
Copy link

ycopin commented Sep 21, 2023

Hi, is there any similar trick to use pytest within a notebook, without resorting to extra-dependencies such as ipytest?

@SergiyKolesnikov
Copy link
Author

Hi, is there any similar trick to use pytest within a notebook, without resorting to extra-dependencies such as ipytest?

Unfortunately, I do not know a trick like that. I have researched this some time ago and the only two options that I found were either using an Jupyter extension or exporting the notebook to a Python file.

@ycopin
Copy link

ycopin commented Sep 24, 2023

Thanks. I opened a feature request on pytest, let's see what happens with no success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment