Skip to content

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

Closed
@TylerYep

Description

@TylerYep

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions