pytest (It should fail)pytesttest_functionname_caseBefore testing: - Your code should live in a .py file, e.g. my_module.py - Tests should go in a separate file: test_my_module.py
test_my_module.py:
Expect output like:
β¬οΈ Good! The test is failing as expected.
my_module.py:
Re-run pytest:
β Green means good!
π« Too much in one test - Hard to precisely understand what failed and why
π« Testing implementation details - Tests should focus on what your function does and outputs, not how it does it
π« Skipping tests for βjust a scriptβ - Scripts evolve fast β Make testable functions early and part of your default workflow
π« Functions that are hard to test - If a function: - Has side effects - Does too many things - Depends on global state
β‘οΈ It might need to be split into smaller pieces
π‘ If itβs hard to write a simple test, your function may need refactoring!