Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@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