Skip to content

test: remove pytest.skip when a package is not installed #152

@cadenmyers13

Description

@cadenmyers13

Problem

Some of these older tests skip pytest if a package is not imported into the developer's environment. This looks something like the following,

def test_pickling(diffpy_structure_available):
    """Test pickling of DiffpyStructureParSet."""
    if not diffpy_structure_available:
        pytest.skip("diffpy.structure package not available")
    from diffpy.structure import Atom, Structure

    stru = Structure([Atom("C", [0, 0.2, 0.5])])
    dsps = DiffpyStructureParSet("dsps", stru)
    data = pickle.dumps(dsps)
    dsps2 = pickle.loads(data)
    assert 1 == len(dsps2.atoms)
    assert 0.2 == dsps2.atoms[0].y.value
    return

This is not the best behavior. If the developer doesnt have this package installed into their environment, this test should fail and they should install the necessary package.

Proposed solution

Remove the if not <package_name>: conditional and its associated fixture(s) in conftest.py. The test should then look something like this,

def test_pickling():
    """Test pickling of DiffpyStructureParSet."""
    from diffpy.structure import Atom, Structure

    stru = Structure([Atom("C", [0, 0.2, 0.5])])
    dsps = DiffpyStructureParSet("dsps", stru)
    data = pickle.dumps(dsps)
    dsps2 = pickle.loads(data)
    assert 1 == len(dsps2.atoms)
    assert 0.2 == dsps2.atoms[0].y.value
    return

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions