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

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

Closed
sobolevn opened this issue Oct 4, 2022 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 4, 2022

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.

@sobolevn sobolevn added the type-bug An unexpected behavior, bug, or error label Oct 4, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 4, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 4, 2022
orsenthil pushed a commit that referenced this issue Oct 5, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 5, 2022
miss-islington added a commit that referenced this issue Oct 5, 2022
…-97838) (GH-97887)

(cherry picked from commit c3648f4)


Co-authored-by: Nikita Sobolev <[email protected]>

Automerge-Triggered-By: GH:orsenthil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants