Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue May 3, 2021 · 0 comments

Comments

@aewallwi
Copy link
Collaborator

aewallwi commented May 3, 2021

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 #112 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant