.. _UseAssertIsNotNoneRule:

======================
UseAssertIsNotNoneRule
======================

Discourages use of ``assertTrue(x is not None)`` and ``assertFalse(x is not None)`` as it is deprecated (https://docs.python.org/3.8/library/unittest.html#deprecated-aliases).
Use ``assertIsNotNone(x)`` and ``assertIsNone(x)``) instead.


-------
Message
-------
"assertTrue" and "assertFalse" are deprecated. Use "assertIsNotNone" and "assertIsNone" instead.
See https://docs.python.org/3.8/library/unittest.html#deprecated-aliases

----------------
Has Autofix: Yes
----------------

-------------------
VALID Code Examples
-------------------

# 1:







.. code-block:: python

            self.assertIsNotNone(x)




# 2:







.. code-block:: python

            self.assertIsNone(x)




# 3:







.. code-block:: python

            self.assertIsNone(None)




.. container:: toggle


    # 4:







    .. code-block:: python

                self.assertIsNotNone(f(x))





    # 5:







    .. code-block:: python

                self.assertIsNone(f(x))





    # 6:







    .. code-block:: python

                self.assertIsNone(object.key)





    # 7:







    .. code-block:: python

                self.assertIsNotNone(object.key)





---------------------
INVALID Code Examples
---------------------

# 1:







.. code-block:: python

            self.assertTrue(a is not None)




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -self.assertTrue(a is not None)
    +self.assertIsNotNone(a)

# 2:







.. code-block:: python

            self.assertTrue(not x is None)




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -self.assertTrue(not x is None)
    +self.assertIsNotNone(x)

# 3:







.. code-block:: python

            self.assertTrue(f() is not None)




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1 @@
    -self.assertTrue(f() is not None)
    +self.assertIsNotNone(f())

.. container:: toggle


    # 4:







    .. code-block:: python

                self.assertTrue(not x is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertTrue(not x is not None)
        +self.assertIsNone(x)


    # 5:







    .. code-block:: python

                self.assertTrue(f(x) is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertTrue(f(x) is not None)
        +self.assertIsNotNone(f(x))


    # 6:







    .. code-block:: python

                self.assertTrue(x is None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertTrue(x is None)
        +self.assertIsNone(x)


    # 7:







    .. code-block:: python

                self.assertFalse(x is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(x is not None)
        +self.assertIsNone(x)


    # 8:







    .. code-block:: python

                self.assertFalse(not x is None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(not x is None)
        +self.assertIsNone(x)


    # 9:







    .. code-block:: python

                self.assertFalse(f() is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(f() is not None)
        +self.assertIsNone(f())


    # 10:







    .. code-block:: python

                self.assertFalse(not x is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(not x is not None)
        +self.assertIsNotNone(x)


    # 11:







    .. code-block:: python

                self.assertFalse(f(x) is not None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(f(x) is not None)
        +self.assertIsNone(f(x))


    # 12:







    .. code-block:: python

                self.assertFalse(x is None)




    Autofix:

    .. code-block:: python

        --- 
        +++ 
        @@ -1 +1 @@
        -self.assertFalse(x is None)
        +self.assertIsNotNone(x)

