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

Type Error using patch decorator for 7.0.0rc1 #9414

Closed
4 tasks done
rohitsheth opened this issue Dec 15, 2021 · 5 comments
Closed
4 tasks done

Type Error using patch decorator for 7.0.0rc1 #9414

rohitsheth opened this issue Dec 15, 2021 · 5 comments
Labels
plugin: nose related to the nose integration builtin plugin type: regression indicates a problem that was introduced in a release which was working previously
Milestone

Comments

@rohitsheth
Copy link

rohitsheth commented Dec 15, 2021

    @patch("packge.class.method")
    def setup(self, mock_method):

The mentioned method is with decorated @staticmethod

Error

    @wraps(func)
    def patched(*args, **keywargs):
        with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):
>           return func(*newargs, **newkeywargs)
E           TypeError: setup() takes 2 positional arguments but 3 were given

.eggs/mock-4.0.3-py3.6.egg/mock/mock.py:1346: TypeError

When I use pytest 6.2.5 I do not see this error. This error happens when using pytest 7.+

Package Version
coverage 5.6b1
pytest 7.0.0rc1
pytest-cov 2.11.1
PyHamcrest 2.0.2
mock 4.0.3
tomli 1.2.3

OS: Linux 14.04.6 LTS, Trusty Tahr
Python: Python 3.6.8

Note: Truncated details due to limitations on what I can share about the code and packages.
I can answer further questions if this information is unsufficient.

Quick check-list while reporting bugs:

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible
@The-Compiler
Copy link
Member

The-Compiler commented Dec 16, 2021

It'd be good to have a minimal, complete reproducer demonstrating the issue - I was able to cook one up though:

issue9414.py:

class Cls:

    @staticmethod
    def meth():
        pass

test_9414.py:

from unittest.mock import patch

class TestNothing:

    @patch("issue9414.Cls.meth")
    def setup(self, mock_method):
        pass

    def test_x(self):
        pass

Bisected to 89f0b5b from #9273 ("nose: fix class- and module-level fixture behavior"), cc @bluetech

@The-Compiler The-Compiler added this to the 7.0 milestone Dec 16, 2021
@The-Compiler The-Compiler added plugin: nose related to the nose integration builtin plugin type: regression indicates a problem that was introduced in a release which was working previously labels Dec 16, 2021
@bluetech
Copy link
Member

@rohitsheth Thanks for testing the rc!

The method name setup has a special meaning in test classes - see https://docs.pytest.org/en/latest/how-to/nose.html. Pytest 7.0 has some fixes in this area which make the patching fail, but technically the conflict also exists in previous versions.

You can fix the problem either by using a different name, or by disabling the nose compatibility by passing -p no:nose to pytest (can also be added to addopts config).

@The-Compiler
Copy link
Member

I think that was the intention here though: Having some kind of special setup method which does some patching, no?

@rohitsheth
Copy link
Author

Yes, the intention was to have a special setup method.
I do have a workaround by changing the name, thank you for the link.
Additionally, thank you adding complete reproducible code, I couldn't share mine due to work limitations.

@bluetech
Copy link
Member

I'm closing for #9391 because it's the same underlying issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: nose related to the nose integration builtin plugin type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

3 participants