Skip to content

Misleading DeprecationWarning in unittest: It is deprecated to return a value!=None #97837

@sobolevn

Description

@sobolevn

In python != and is not are two different things.
Right now the deprecation warning says !=, let's see if that's true:

from unittest import TestCase, main

class Nothing:
    def __eq__(self, o):
        return o is None

class TestExample(TestCase):
    def test_method(self):
        n = Nothing()
        self.assertEqual(n, None)
        return n

main()

It still raises this:

/Users/sobolev/Desktop/cpython/Lib/unittest/case.py:678: DeprecationWarning: It is deprecated to return a value!=None from a test case (<bound method TestExample.test_method of <__main__.TestExample testMethod=test_method>>)
  return self.run(*args, **kwds)
.
----------------------------------------------------------------------
Ran 1 test in 0.003s

OK

I believe that this is misleading. The proper message should say: It is deprecated to return a value that is not None from a test case

I will send a PR with the fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy