Skip to content

Case sets #262

Open
Open
@jlorieau

Description

@jlorieau

I'm relatively new to pytest cases, so this feature may already be implemented in some way that I have not found.

I have a series of data test cases in a root file for multiple datasets. These include reference datasets and datasets that have been modified in some specific way by an external program:

cases.py:

def data_reference(): ...
def data_procedure1a(): ...
def data_procedure1b(): ...
def data_procedure2():...

For individual cases, I can import these pretty easily:

test.py

@parametrize_with_cases('dataset', prefix='data_', cases='cases')

However, I have many tests that require modifying the reference by a procedure implemented in my program, and comparing to the data from a different data test case.

Option 1
So far, I add the following to cases.py:

cases.py

def case_procedure1a():
    return data_reference(), data_procedure1a()

def case_procedure1b():
    return data_reference(), data_procedure1b()

Then I call this test case for a test that requires the matching of 2 datasets:

test.py

@parametrize_with_cases('reference,modified', prefix='case_', cases='cases', glob=('*procedure1*')

Developing test cases for all possible pairings gets pretty unwieldy quickly.

Option 2
An alternative would be to import my test cases and parameterize them:

test.py

import pytest
from .cases import data_reference, data_procedure1a, data_procedure1b

@pytest.mark.parameterize('reference,modified', 
    ((data_reference(), data_procedure1a()),
     (data_reference(), data_procedure1b()))

However, this approach requires importing the test case functions, and it directly couples my test code to the case code.

I wonder whether there is a procedure to test data test case pairs or triplets in which I could reference these by id, tag or something else. I suspect that this may require some additional coding, which is why this might be a feature request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions