Closed
Description
Running pytest master I see warnings from XFAIL tests about asserting None. The warnings suggests to change the assert to assert obj is None
but the reason we are asserting None
is because the test fails (hence XFAIL
).
I don't think these warnings should be emitted from XFAIL tests.
Using pytest master:
import pytest
@pytest.mark.XFAIL
def test_f():
assert g()
def g():
# Shouldn't return None but doesn't work properly...
return None
Running the tests gives:
$ pytest test_f.py
====================================================== test session starts =======================================================
platform darwin -- Python 2.7.10, pytest-4.1.1, py-1.7.0, pluggy-0.8.0
rootdir: /Users/enojb/current/sympy/pytest, inifile: tox.ini
plugins: xdist-1.26.0, forked-0.2, doctestplus-0.3.0.dev0
collected 1 item
test_f.py F [100%]
============================================================ FAILURES ============================================================
_____________________________________________________________ test_f _____________________________________________________________
@pytest.mark.XFAIL
def test_f():
> assert g()
E PytestWarning: asserting the value None, please use "assert is None"
test_f.py:5: PytestWarning
==================================================== short test summary info =====================================================
FAIL test_f.py::test_f
==================================================== 1 failed in 0.08 seconds ====================================================
Activity
blueyed commentedon Jan 12, 2019
What would you assert if it worked? Also just
assert g()
?Have you considered using
assert g() is not None
then?RonnyPfannschmidt commentedon Jan 12, 2019
Xfail should be lowercase we need strict marks as default
oscarbenjamin commentedon Jan 12, 2019
I'm seeing a few warnings haven't worked through them yet but here's one: https://github.com/sympy/sympy/blob/sympy-1.3/sympy/assumptions/tests/test_matrices.py#L41
It's not clear to me that that test should be asserting
is not None
. It possibly could be changed tois True
but I'm not sure.asottile commentedon Jan 13, 2019
I believe the mistake here is
pytest.mark.XFAIL
vspytest.mark.xfail
trying in a little script this works as expected, even with
assert None
:pytest.mark.xfail
pytest.mark.XFAIL
switching to the incorrect name:
asottile commentedon Jan 13, 2019
unrelated, I'd suggest using
pytest
instead of the deprecatedpy.test
hereoscarbenjamin commentedon Jan 20, 2019
Maybe I'm misunderstanding something here. For my example above
test_f.py
at the top of this issue I changed it fromXFAIL
toxfail
and the problem does indeed go away but only if I'm running in the pytest root directory:asottile commentedon Jan 20, 2019
that output looks correct to me, are you expecting
xfail
to silence the warning?The reason it "appears" to silence the warning when run from
pytest
is we configure warnings-as-errors: here -- in reality it's upgrading the warning to an exception (which is gobbled by xfail)oscarbenjamin commentedon Jan 20, 2019
Okay I've reread everything above and I understand now.
The actual code I'm testing uses
py.test.mark.xfail
anyway. I can change that topytest.mark.xfail
but either way I see this problem.After initially reading the comments above I was hoping that changing to
xfail
would remove these warnings because I don't think it makes sense to warn about this in a test that is already marked asxfail
. I'll probably just fix this in Sympy though by changing the tests.asottile commentedon Jan 20, 2019
maybe the feature request is "xfail silences warnings" -- I think that could be considered but there's probably a lot of cases where you want the warnings even when you expect it to fail? I haven't put much thought to it.
oscarbenjamin commentedon Jan 20, 2019
I think
xfail silences warnings
could be a feature request but that's not what I would propose.I've read #3191 and #4146 and I don't understand the rationale for this change. A user who is confused and writes
assert mock.assert...
will immediately see a test failure because they are assertingNone
. I can see that it might be worthwhile to improve the test report forassert None
when a test fails.Adding this as a warning means that it will also show up for
xfail
tests (which is pointless).davidlowryduda commentedon Feb 14, 2019
I believe that this is resolved in sympy #15817 and that this issue can now be closed. I therefore suggest that this issue be closed.
oscarbenjamin commentedon Feb 14, 2019
I would say that the issue is worked around in sympy. I still think this should be fixed in pytest.
davidlowryduda commentedon Feb 15, 2019
Yes, now that you mention it, I agree. Thanks for your quick response.
29 remaining items