question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning about assert None from XFAIL tests

See original GitHub issue

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 ====================================================

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:30 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Nov 19, 2019

@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

1reaction
asottilecommented, 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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found