How to Test Raising and Not Raising an Exception Using Only One Function in pytest

preview_player
Показать описание
In this pytest tutorial, I'll show you how to write a single test function that tests if an exception is raised or not.

First, we implement a division function, which we want to test.

Secondly, pytest's raises function is used to test that a specific exception is raised.

Lastly, I'll show you how you can use a null context in combination with the parametrize marker to test whether an exception is raised or not in only one function!

GitHub Repository

SUBSCRIBE to become a Pythonista!

Follow me on Twitter!

Check out my website for more!

~~~~~~~~~~ OUTLINE ~~~~~~~~~~
00:00 Introduction
00:44 Test that exception is raised
01:54 Test that exception is not raised

#python #pytest #testing
Рекомендации по теме
Комментарии
Автор

Concise and clear. Thanks for the video!

harima
join shbcf.ru