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

PT009 changes assertFalse() into assert … is False #2456

Closed
spaceone opened this issue Feb 1, 2023 · 4 comments
Closed

PT009 changes assertFalse() into assert … is False #2456

spaceone opened this issue Feb 1, 2023 · 4 comments

Comments

@spaceone
Copy link
Contributor

spaceone commented Feb 1, 2023

$ cat foo.py
import unittest


class TestFoo(unittest.TestCase):

    def test_foo(self):
        self.assertFalse(None)


unittest.main()
$ ruff --select PT009 --fix foo.py
Found 1 error (1 fixed, 0 remaining).
$ cat foo.py
import unittest


class TestFoo(unittest.TestCase):

    def test_foo(self):
        assert None is False


unittest.main()
$ python3 foo.py
F
======================================================================
FAIL: test_foo (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "foo.py", line 7, in test_foo
    assert None is False
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
@charliermarsh
Copy link
Member

Is this incorrect? :)

@edgarrmondragon
Copy link
Contributor

I guess assertFalse is really checking for falsy values. Maybe the right fix should be

-         self.assertFalse(None)
+         not None

@spaceone
Copy link
Contributor Author

spaceone commented Feb 2, 2023

https://github.com/python/cpython/blob/main/Lib/unittest/case.py#L705-L709
I'll do a PR.

@charliermarsh
Copy link
Member

Fixed by #2476.

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

3 participants