C · Testing · intermediate · Week 3 · Chapter 7 of 13
pytest fundamentals
Arrange-act-assert. test_ prefix. assert directly. pytest discovers tests/ automatically.
Path progress49%
Step 1 of 3
First tests
test_is_valid_email_true(), test_is_valid_email_false(). No unittest boilerplate.
Example
# tests/test_helpers.py
from src.helpers import is_valid_email
def test_valid_email():
assert is_valid_email("a@b.com") is True
def test_invalid_email():
assert is_valid_email("nope") is FalseDo this now
5 pytest tests for helpers from earlier chapters. pytest -v.
Was this step clear?
Chapter learning outcomes
- pytest discovery
- assert style
- Running pytest
- Test naming
Clear these before you leave
Side quest
Config tests
Test load_config with missing file raises or returns default.