HERA-Team / uvtools

Tools useful for the handling, visualization, and analysis of interferometric data.
MIT License
1 stars 1 forks source link

Make these their own tests. I like to make error tests very specific, so it's obvious when things in the code have been changed. For example, suppose the function ``func`` raises a ``ValueError`` with error message ``msg`` when ran with parameters ``args``. I would then write a test along the lines of #122

Open aewallwi opened 3 years ago

aewallwi commented 3 years ago

Make these their own tests. I like to make error tests very specific, so it's obvious when things in the code have been changed. For example, suppose the function func raises a ValueError with error message msg when ran with parameters args. I would then write a test along the lines of

def test_func_error():
    args = [bad, parameter, values]
    msg = "whatever the expected message is"
    with pytest.raises(ValueError) as err:
        func(*args)
    assert err.value.args[0] == msg

For long error messages, I usually just check that part of the expected message is in the actual error message, e.g. assert "bit of text from message" in err.value.args[0].

_Originally posted by @r-pascua in https://github.com/HERA-Team/uvtools/pull/112#discussion_r624119060_