Warning about assert None from XFAIL tests
See original GitHub issueRunning 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 ====================================================
Issue Analytics
- State:
- Created 5 years ago
- Comments:30 (26 by maintainers)
Top Results From Across the Web
How to use skip and xfail to deal with tests that cannot succeed
A skip means that you expect your test to pass only if some conditions are met, otherwise pytest should skip running the test...
Read more >Show Source - Pandas - PyData |
Write a new test that asserts a warning is issued when calling with the deprecated ... None]] = [] or .. code-block:: python...
Read more >Is it possible to change PyTest's assert statement behaviour in ...
When p.interaction(None, t) returns, pytest continues with the next test, unless p.quitting is set to True (at which point pytest then ...
Read more >pytest Documentation - Read the Docs
2.13 How to use skip and xfail to deal with tests that cannot succeed ... Use the raises helper to assert that some...
Read more >Reference — pytest documentation
xfail (reason='')[source]¶. xfail an executing test or setup functions with the given reason. ... Tutorial: Asserting warnings with the warns function.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nicoddemus @RonnyPfannschmidt @blueyed I’m convinced we should remove this warning – I’ve yet to see a helpful case and I’ve seen a few pretty unhelpful cases – let me know what you think
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)