Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PytestAssertRewriteWarning: asserting the value None, please use "assert is None" #6203

Closed
KrishnaKantPrajapat opened this issue Nov 16, 2019 · 5 comments

Comments

@KrishnaKantPrajapat
Copy link

Here is the minimal demo that is working fine on local machine but showing warning while submitting for a handson

<body>
  <video width="320" height="200" controls preload="none" poster="https://cdn12.picryl.com/photo/2016/12/31/lego-stones-plastic-education-8b9a7d-1024.jpg">
    <source src="video.mp4" type="video/mp4">
</video>

<video width="320" height="200" controls preload="none" poster="https://cdn12.picryl.com/photo/2016/12/31/lego-stones-plastic-education-8b9a7d-1024.jpg">
    <source src="video.mp4" type="video/mp4">
</video>

<video width="320" height="200" controls preload="none" poster="https://cdn12.picryl.com/photo/2016/12/31/lego-stones-plastic-education-8b9a7d-1024.jpg">
    <source src="video.mp4" type="video/mp4">
</video>

</body>

And here is the warning message

test/test_webpage.py::TestWebpage::test_indexpage

  /projects/challenge/test/test_webpage.py:28: PytestAssertRewriteWarning: asserting the value None, please use "assert is None"

    assert self._index.find('video', {'controls': '', 'preload': ''})

-- Docs: https://docs.pytest.org/en/latest/warnings.html

For below tests

assert self._index.find('video', {'autoplay': ''})
        assert self._index.find('video', {'controls': '', 'preload': ''})
        assert self._index.find('video', {'poster': 'https://cdn12.picryl.com/photo/2016/12/31/lego-stones-plastic-education-8b9a7d-1024.jpg'})
@bluetech
Copy link
Member

The warning is intentional. It suggests to you to change your assertions as follows:

assert self._index.find('video', {'autoplay': ''}) is not None
assert self._index.find('video', {'controls': '', 'preload': ''}) is not None
assert self._index.find('video', {'poster': 'https://cdn12.picryl.com/photo/2016/12/31/lego-stones-plastic-education-8b9a7d-1024.jpg'}) is not None

You can see issue #3191 for the rationale for the warning. Let us know if this isn't clear enough.

@Vaish-09
Copy link

@bluetech Still after giving autoplay="autoplay" in my video tag, I get the below error:
test/test_webpage.py::TestWebpage::test_indexpage

/projects/challenge/test/test_webpage.py:27: PytestAssertRewriteWarning: asserting the value None, please use "assert is None"

assert self._index.find('video', {'autoplay': ''})

Can you please help me out?

@bluetech
Copy link
Member

Change it to the following:

assert self._index.find('video', {'autoplay': ''}) is not None

@nagulapatigirireddy
Copy link

Hi , I am having same issue. Please help with what changes to be made for below code?

`

<title>Destiny</title> `

@nicoddemus
Copy link
Member

@nagulapatigirireddy,

You did not post any code, but the change is simple. It means you have this:

assert <expr>

You just need to change it to:

assert <expr> is not None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants