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

Deprecated assertEquals (and similar methods) don't work in marbles #85

Open
leifwalsh opened this issue Jul 7, 2018 · 3 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@leifwalsh
Copy link
Contributor

leifwalsh commented Jul 7, 2018

  • marbles.core version: 0.9.5
  • marbles.mixins version: 0.9.5
  • Python version: 3.6.5
  • Operating System: Linux

Description

Tried to run a unittest test that uses the deprecated name assertEquals instead of assertEqual.

What I Did

import marbles.core

class MyTestCase(marbles.core.TestCase):

    def test_assertEqual_success(self):
        x = 1
        y = 1
        self.assertEqual(x, y)

    def test_assertEqual_failure(self):
        x = 1
        y = 2
        self.assertEqual(x, y)

    def test_assertEquals_success(self):
        x = 1
        y = 1
        self.assertEquals(x, y)

    def test_assertEquals_failure(self):
        x = 1
        y = 2
        self.assertEquals(x, y)

The assertEquals tests fail with the following stack:

======================================================================
ERROR: test_deprecated_assertEquals_failure (tests.test_marbles.InterfaceTestCase) (use_annotated_test_case=False)
Does the deprecated assertEquals method work on failure?
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leif/git/marbles/marbles/core/tests/test_marbles.py", line 373, in test_deprecated_assertEquals_failure
    self.case.test_deprecated_assertEquals_failure()
  File "/home/leif/git/marbles/marbles/core/tests/test_marbles.py", line 93, in test_deprecated_assertEquals_failure
    self.assertEquals(x, y)
  File "/home/leif/git/marbles/marbles/core/marbles/core/marbles.py", line 538, in wrapper
    return attr(*args, msg=annotation, **kwargs)
  File "/usr/lib64/python3.6/unittest/case.py", line 1323, in deprecated_func
    return original_func(*args, **kwargs)
TypeError: assertEqual() missing 1 required positional argument: 'second'

======================================================================
ERROR: test_deprecated_assertEquals_success (tests.test_marbles.InterfaceTestCase) (use_annotated_test_case=False)
Does the deprecated assertEquals method still work?
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leif/git/marbles/marbles/core/tests/test_marbles.py", line 364, in test_deprecated_assertEquals_success
    self.case.test_deprecated_assertEquals_success()
  File "/home/leif/git/marbles/marbles/core/tests/test_marbles.py", line 88, in test_deprecated_assertEquals_success
    self.assertEquals(x, y)
  File "/home/leif/git/marbles/marbles/core/marbles/core/marbles.py", line 538, in wrapper
    return attr(*args, msg=annotation, **kwargs)
  File "/usr/lib64/python3.6/unittest/case.py", line 1323, in deprecated_func
    return original_func(*args, **kwargs)
TypeError: assertEqual() missing 1 required positional argument: 'second'

----------------------------------------------------------------------

Expected behavior

I expected assertEqual and assertEquals to behave the same. Instead, assertEqual does the expected thing, while assertEquals fails with a TypeError

@leifwalsh leifwalsh added the bug Something isn't working label Jul 7, 2018
@leifwalsh leifwalsh self-assigned this Jul 7, 2018
@leifwalsh
Copy link
Contributor Author

I ran this in pdb and found the following:

> /usr/lib64/python3.6/unittest/case.py(1322)deprecated_func()
-> return original_func(*args, **kwargs)
(Pdb) p args
(<tests.test_marbles.ExampleTestCase testMethod=runTest>, 1)
(Pdb) p kwargs
{'msg': {'msg': 2, 'note': None}}

It seems that we're incorrectly assuming the last argument here is the msg and packaging that up, rather than forwarding it along.

@leifwalsh
Copy link
Contributor Author

This is because we inspect the method signature to find the msg argument (here) to figure out which one to pull out, but since this deprecated method's signature is actually (*args, **kwargs), we default to pulling the last argument out as msg, when in actuality we should pass through at this level and catch the msg argument when it calls through to assertEqual.

Not sure exactly what to do here, perhaps we should detect when the assertion method is one of these passthroughs

leifwalsh added a commit that referenced this issue Jul 7, 2018
…ters

This deals with the "deprecated assertion names" like assertEquals forwarding to assertEqual, and possibly
others like them.

Closes #85
leifwalsh added a commit that referenced this issue Jul 7, 2018
…ters

This deals with the "deprecated assertion names" like assertEquals forwarding to assertEqual, and possibly
others like them.

Closes #85
leifwalsh added a commit that referenced this issue Jul 7, 2018
…ters

This deals with the "deprecated assertion names" like assertEquals forwarding to assertEqual, and possibly
others like them.

Closes #85
@tirkarthi
Copy link

Note : In Python 3.11 the deprecated aliases have been removed in python/cpython#28268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants