Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Missing output in pytest magics #2
When I run a cell using the new magics, I don't see the complete output that I expect from pytest. On the command line pytest typically prints detailed information about an assertion, but all the magic prints is
For example, given this function:
the command line shows this:
but the cell magic just shows:
This makes it hard to demo one of pytest's strengths, it's ability to introspect assertions and pinpoint the problem.
I looked through the code a bit, but nothing struck me as an obvious culprit. Is there something I can do to make this work with flags to
Could you detail how you call
%%run_pytest def test_sorted(): assert sorted([4, 2, 1, 6]) == [1, 2, 3, 4]
The full notebook can be found here (I added
I'm totally baffled here. Whenever I use ipytest from a jupyter notebook, I don't see the expected diffs in the output. I've tried this with my own notebooks as well as with the examples provided with
When I run pytest from the command line I see the proper diffs, so it's not some problem with pytest.
This problem appears even with the
# set the file name (required) __file__ = 'Magics.ipynb' # add ipython magics import ipytest.magics import pytest
%%run_pytest[clean] def test_sorted(): assert sorted([4, 2, 1, 6]) == [1, 2, 3, 4]
========================================= test session starts ========================================== platform darwin -- Python 3.5.2, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 rootdir: /Users/sixtynorth/projects/ipytest, inifile: collected 1 items Magics.py F =============================================== FAILURES =============================================== _____________________________________________ test_sorted ______________________________________________ def test_sorted(): > assert sorted([4, 2, 1, 6]) == [1, 2, 3, 4] E AssertionError <ipython-input-5-f12e7a50e0c6>:3: AssertionError ======================================= 1 failed in 0.02 seconds =======================================
As I mentioned, I've tried this across a few machines which don't share any state, so I don't think it's some sort of configuration options I've somehow set somewhere.
Is it possible that you've got some setting somewhere that's letting your notebooks show more output? I'm grasping at straws here, but this is pretty mysterious.
Also, have you tried a fresh, isolated installation somewhere to see if you can reproduce this behavior?
Thanks for reminding me of this issue. I pushed a new release as
Does this change fit your needs?
For completeness, you can use the magics as in:
## Option 1 # cell 1 import ipytest import ipytest.magics ___file__ = 'Untitled.ipynb' # cell 2, separate call to `run_ipytest` %%rewrite_asserts def test_foo(): assert [1, 2] == [2, 3] # cell 3 ipytest.run_pytest()
## Option 2 # cell 1 import ipytest.magics ___file__ = 'Untitled.ipynb' # cell 2 run_pytest magic %%run_pytest def test_bar(): assert [2, 3] == [3, 4]