Skip to content

Enable @parametrize for test classes even if it uses a fixture #250

Open
@Gutifarra

Description

@Gutifarra

I'm currently using fixtures as a base to generate cases with, in order to perform a bunch of tests which are grouped into various classes. An simple example which illustrates something similar to what I'm doing:

class A:
    pass

@fixture
def create_a():
    return A()

def case_a_1(create_a):
    return create_a, 1

def case_a_2(create_a):
    return create_a, 2


@parametrize_with_cases("a", cases=".")
class tests:
    def test_check_a_exists(self, a):
        assert a

If I attempt to parametrize the actual tests class, pytest-cases raises a NotImplementedError:

E NotImplementedError: @parametrize can not be used to decorate a Test class when the argvalues contain at least one reference to a fixture.

Is there any particular reason for this not being supported? I'm not sure if this is just me designing my tests in a way which is incompatible with some fundamental design behind pytest and pytest-cases, or if it's something which should be in a future implementation.

I would expect decorating this class with @parametrize to do exactly the same as if I decorated each of the test functions.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions