You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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].
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 aValueError
with error messagemsg
when ran with parametersargs
. I would then write a test along the lines ofFor 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)
The text was updated successfully, but these errors were encountered: