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 upMissing output in pytest magics #2
Comments
This comment has been minimized.
This comment has been minimized.
Could you detail how you call %%run_pytest
def test_sorted():
assert sorted([4, 2, 1, 6]) == [1, 2, 3, 4] output:
With The full notebook can be found here (I added |
This comment has been minimized.
This comment has been minimized.
Maybe the flag |
This comment has been minimized.
This comment has been minimized.
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 CELL 2 %%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? |
This comment has been minimized.
This comment has been minimized.
Yes, I can reproduce your behavior. Apparently the pytest version is to blame. For I have to have a look whether this can be fixed and, if so, how. |
This comment has been minimized.
This comment has been minimized.
OK, it's good that you've at least got a lead on it. Let me know if you need a hand looking into anything. |
This comment has been minimized.
This comment has been minimized.
DenisGorbachev
commented
Apr 23, 2018
Same issue with the following package versions:
Is it possible to provide any additional info to help debug the issue? |
This comment has been minimized.
This comment has been minimized.
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] |
This comment has been minimized.
This comment has been minimized.
DenisGorbachev
commented
Apr 23, 2018
@chmp Yes, |
This comment has been minimized.
This comment has been minimized.
Perfect. Happy to help :). |
abingham commentedJan 3, 2017
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
E AssertionError
.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
run_pytest
? Or is there a code change you can make to fix this?