Skip to content

pytest_generate_tests does not work on @staticmethod functions in superclass #8193

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
TylerYep opened this issue Dec 26, 2020 · 2 comments
Closed
Labels
topic: parametrize related to @pytest.mark.parametrize

Comments

@TylerYep
Copy link

TylerYep commented Dec 26, 2020

I am encountering an error when using pytest_generate_tests with @staticmethod:

My goal is to create a MaxFlow class that other test files can inherit from and insert fixtures to all tests within the MaxFlow class. Everything is working fine, except for this minor edge case that requires me to add self instead of @staticmethod.

pytest:

In test_that_gives_an_error: function uses no argument 'max_flow_fn'
# max_flow.py
class MaxFlow:
    @staticmethod
    def test_that_gives_an_error(max_flow_fn):
        ...

    def test_that_works_correctly(self, max_flow_fn):
        ...
# test_max_flow.py
class TestKarp(MaxFlow):
    max_flow_fn = edmonds_karp_max_flow_fn


def pytest_generate_tests(metafunc):
    metafunc.parametrize("max_flow_fn", [metafunc.cls.max_flow_fn])

Pytest 6.2.0
Mac OS

@Zac-HD Zac-HD added the topic: parametrize related to @pytest.mark.parametrize label Dec 27, 2020
@antonblr
Copy link
Member

Apparently #8205 addresses this issue as well.

@bluetech
Copy link
Member

bluetech commented Jan 2, 2021

Fixed by #8205

@bluetech bluetech closed this as completed Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize
Projects
None yet
Development

No branches or pull requests

4 participants