pytest: Check if an Exception Is Raised (Or Not)
pytest: Check if an Exception Is Raised (Or Not)
Time is a precious resource so I won’t waste yours. Here’s how you can assert an exception is raised and how to check that in pytest. Solution: Use pytest.raises import pytest def test_raises_exception(): with pytest.raises(ZeroDivisionError): 1 / 0 And here’s how you assert no exception is raised. Solution: Enclose your code in a try/except block and if the code raises, you can catch it and…
View On WordPress












