Skip to content

Use pytest.mark.parametrize to cut down on duplicate tests #100

@JoelLucaAdams

Description

@JoelLucaAdams

There is an issue where we have two tests that check the same thing where the only difference is which library is used. E.g.

def test_drop_variables_original():
    with open_dataset(
        TEST_FILES_DIR / "0000.sdf",
        drop_variables=["Electric_Field/Ex", "Electric_Field/Ey"],
    ) as df:
        assert "Electric_Field_Ex" not in df
        assert "Electric_Field_Ey" not in df


def test_xr_drop_variables_original():
    with xr.open_dataset(
        TEST_FILES_DIR / "0000.sdf",
        drop_variables=["Electric_Field/Ex", "Electric_Field/Ey"],
    ) as df:
        assert "Electric_Field_Ex" not in df
        assert "Electric_Field_Ey" not in df

To avoid this duplication of tests that accomplish the same goal but with different signatures we should use the pytest decorator as suggested by @LiamPattinson.

@pytest.mark.parametrize("xrlib", (xr, sdfxr))
def test_drop_variables_original():
    with xrlib.open_dataset(
        TEST_FILES_DIR / "0000.sdf",
        drop_variables=["Electric_Field/Ex", "Electric_Field/Ey"],
    ) as df:
        assert "Electric_Field_Ex" not in df
        assert "Electric_Field_Ey" not in df

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions