jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.73k stars 4.97k forks source link

FEATURE: Builtin pytest magic #3456

Open pylang opened 6 years ago

pylang commented 6 years ago

There has been some discussion at pytest-dev on adding some way to run pytest in notebooks.

One proposal has been to invoke a magic similar to %matplotlib at the start of the notebook. This would a override the normal assertion output for any cell with pytest's detailed output (see example here).

Can we have a %pytest implemented as one of the builtin magics in jupyter notebooks?

chmp commented 6 years ago

Maybe of interest: I wrote a small package ipytest, which allows to run tests defined inside notebooks.

pylang commented 6 years ago

@chmp You should be commended on a brilliant attempt at tackling this. This is the best option I see so far.

In your README, you identify a few issues that are not obvious to most people and require attention, particularly with clearing the notebook globals when running tests. In the future, I hope there will be more dialog between the jupyter and pytest teams on making a idiomatic solution. Preferably, all the required boilerplate would be:

import pytest

%pytest

I am a bit hesitant to pepper additional magic throughout my notebooks to run tests. It is the only reason I still use nose. ))

chmp commented 6 years ago

@pylang Thanks a lot for the feedback. I understand your comment to have two parts:

Since I do not want to highjack the notebook issue tracker for ipytest issues, I collected my comments here. Feel free to comment and re-open the issue in case the changes do not work for you.