Skip to content

Commit a970b31

Browse files
Merge pull request #37 from TheJacksonLaboratory/match_kwarg
Update pytest.md to mention match kwarg of pytest.raises
2 parents cb19682 + 76fe4a6 commit a970b31

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pytest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ It takes two arguments: a *tuple or string* with the *names* of the parameters y
3939
4040
15. It's time to add explicit exception handling to our functions. You will probably want to do `raise ValueError("array size mismatch")` for the case where arrays sizes are different, and `raise TypeError("arguments should be lists")` for when the arguments are not lists.
4141
42-
16. Now, we can add new test functions named `test_add_arrays_error()` and so on, where we check if errors are being raised correctly. That is done by wrapping our function call with `with pytest.raises(ValueError)`, for example. What happens when you run `pytest` now? Add checks for both possible errors we came up with. What other cases can happen in e.g. `divide_arrays()`?
42+
16. Now, we can add new test functions named `test_add_arrays_error()` and so on, where we check if errors are being raised correctly. That is done by wrapping our function call with `with pytest.raises(ValueError)`, for example. What happens when you run `pytest` now? Add checks for both possible errors we came up with. Better yet, use the [`match` keyword argument](https://docs.pytest.org/en/stable/reference/reference.html#pytest-raises) to check the string and ensure *the right* ValueError was raised! What other cases can happen in e.g. `divide_arrays()`?
4343
4444
17. We have successfully found a way to separate the data to be tested from the code to be tested. `pytest` has an even better way to do that for more complex cases, for example, when you want multiple test functions using the same data. They are called [_fixtures_](https://docs.pytest.org/en/stable/explanation/fixtures.html#about-fixtures).
4545
A _fixture_ is defined as a function that returns something we want to use repeatedly in our tests. `pytest` provides [some fixtures out of the box](https://docs.pytest.org/en/stable/reference/fixtures.html), like the very useful `tmp_path` fixture that gives you a unique temporary location.

0 commit comments

Comments
 (0)