akaihola / ipython_pytest

Pytest magic for IPython notebooks
Other
37 stars 8 forks source link

Problem collecting things #1

Closed russel closed 6 years ago

russel commented 7 years ago

I found this plugin from Austin's question on SO http://stackoverflow.com/questions/41304311/running-pytest-test-functions-inside-a-jupyter-notebook

I cloned the repository and then put a symlink to the Python file in . of the Jupyter notebook kernel. I added the %load in a cell and executed it, then executed the cell creating all the data for the tests and then executed the tests. Sadly this last execution failed with:

============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.5.3, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
benchmark: 3.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=5.00us max_time=1.00s calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /tmp/tmppsvy8zby, inifile: 
plugins: hypothesis-3.6.1, pylint-0.6.0, mock-1.3.0, cov-2.4.0, benchmark-3.0.0
collected 0 items / 1 errors

==================================================================================================== ERRORS =====================================================================================================
________________________________________________________________________________________ ERROR collecting _ipytesttmp.py ________________________________________________________________________________________
_ipytesttmp.py:6: in <module>
    ((a, d, r) for a in algorithms for d, r in dataset))
E   NameError: name 'algorithms' is not defined
============================================================================================ pytest-warning summary =============================================================================================
WP1 None Module already imported so can not be re-written: hypothesis
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================================== 1 pytest-warnings, 1 error in 0.26 seconds ===================================================================================

Clearly things appear to start well, but then things go awry. Is it just that all the test code must be in a single cell, that none of the symbols used in a test can be defined in a different cell?

akaihola commented 6 years ago

@russel, you're exactly right – unfortunately I haven't found a way around this issue. Nothing defined in preceding cells is visible to the test.