Pytest Quick Start Guide
Let's get you up to speed on Pytest, mocking, fixtures, patching, and monkey patching so you can start writing tests quickly! Pytest Fundamentals Pytest is a powerful and easy-to-use testing framework for Python. Installation: pip install pytest Running Tests: Navigate to your project directory in the terminal and run pytest . Pytest automatically discovers test files (files starting with test_ or ending with _test.py ) and test functions/methods (functions starting with test_ ). Assertions: Pytest uses standard Python assert statements. Python def test_addition (): assert 1 + 1 == 2 def test_list_contains (): my_list = [ 1 , 2 , 3 ] assert 2 in my_list Test Classes: You can group related tests into classes. Python class TestCalculator : def test_add ( self ): assert 2 + 3 == 5 def test_subtract ( self ): assert 5 - 2 == 3 Fixtures Fixtures are functions that Pytest runs before (and sometimes after) your te...