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

Most upvoted comments

@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)