Setup and Run A Test With Pytest

Introduction To Pytest

Take your first steps with pytest. See how to setup a python test file, write an example test and then run the test suite.


[0:00] After installing pytest, let's go ahead and make our first Python test file. Now let's add an test function. And we'll include an assertion that we want pytest to check to know if the test should pass or fail.

[0:15] Let's run the pytest command... and we can see that the test passes. Behind the scenes here pytest is ooking for any files in the directory that begin with test and then inside those files it's gonna look for any functions that begin with test to discover any tests to run.

[0:31] Now let's add another test function. This time we are gonna make it purposely fail. Then when we run pytest again we can see that it reports that the test fails and it gives us a bit more information to help debug that a bit further.