Performing pytest test functions inside jupyter laptop

I am working on a presentation on python testing options, and one of the technologies that I want to use for demonstration is pytest. I plan to make a presentation from a jupyter / ipython laptop. Ideally, I would like to be able to define a test function in a cell, and then use pytest to run that particular function; this way I can demonstrate the individual features of pytest, etc.

Is there an existing way to do this? None of the interactive features that I saw in the pytest api seem to match the bill, but I'm certainly not a testing specialist. I would be happy to write a plugin to do this, so any advice on a better approach in this direction would be great.

I saw pytest-ipynb but it doesn't seem to do what I need. If this estimate is incorrect, tips on how to use it will also be useful.

+9
python jupyter-notebook jupyter pytest
source share
2 answers

I created ipython_pytest for this purpose and used it in my PyCon Helsinki 2016 View .

You would use a tool like this:

%%pytest def test_my_stuff(): assert 42 == 42 

Unfortunately, I could not find a way to make the functions and classes defined in the laptop available for testing functions in a test cell. I would appreciate it if someone comes up with a solution for this.

+8
source share

There is a similar module that looks very mature: https://github.com/chmp/ipytest

It is referenced in a module developed by @akaiola and looks more active.

I personally do not use Jupyter, so I have not tested it myself, but it looks like a good solution.

Here is an example from the Github repository ( https://github.com/chmp/ipytest/blob/master/Example.ipynb )

Jupyter Notebook with iPytest

0
source share

All Articles