Python Testing with Pytest
Testing Python code with pytest including test functions, fixtures, and assertions.
Installing Pytest
# Install pytest
pip install pytest
# Check version
pytest --version
Writing Tests
# Test function
def test_addition():
assert 1 + 1 == 2
assert 2 + 2 == 4
Running Tests
# Run all tests
pytest
# Verbose output
pytest -v