pytest: Warning about assert None from XFAIL tests
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 ====================================================
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 30 (26 by maintainers)
Commits related to this issue
- Merge #6 #7 6: Pin pytest to latest version 6.2.3 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.3**. <details> <summary>Changelog</su... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #6 6: Pin pytest to latest version 6.2.3 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.3**. <details> <summary>Changelog</summa... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #3 #4 3: Pin sphinx_rtd_theme to latest version 0.5.1 r=aragilar a=pyup-bot This PR pins [sphinx_rtd_theme](https://pypi.org/project/sphinx_rtd_theme) to the latest release **0.5.1**. *The... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #7 #8 7: Pin sphinx_rtd_theme to latest version 0.5.2 r=aragilar a=pyup-bot This PR pins [sphinx_rtd_theme](https://pypi.org/project/sphinx_rtd_theme) to the latest release **0.5.2**. *The... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #4 4: Pin pytest to latest version 6.2.2 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.2**. <details> <summary>Changelog</summa... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #18 #20 18: Pin pytest to latest version 6.2.4 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.4**. <details> <summary>Changelog<... — committed to aragilar/spaceplot by bors[bot] 3 years ago
- Merge #16 16: Pin pytest to latest version 6.2.4 r=aragilar a=pyup-bot This PR pins [pytest](https://pypi.org/project/pytest) to the latest release **6.2.4**. <details> <summary>Changelog</sum... — committed to aragilar/venv_tools by bors[bot] 3 years ago
@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)