Quick Start
Test Configuration
pytest.ini
Main pytest configuration:pytest.ini
The
--reuse-db flag reuses the test database between runs for faster execution. Use --create-db to recreate it.pyproject.toml Configuration
pyproject.toml
Test Organization
Tests are organized by app and functionality:Collection App Tests
Test Types
Model Tests (test_models.py)
Model Tests (test_models.py)
Test Django models:
- Model creation and validation
- Field constraints
- Model methods
- Relationships
View Tests (test_views/)
View Tests (test_views/)
Test Django views:
- URL resolution
- View responses
- Form handling
- Permission checks
Service Tests (test_services.py)
Service Tests (test_services.py)
Test business logic in the service layer:
- Service methods
- Business rules
- Data transformations
- Error handling
Form Tests (test_forms.py)
Form Tests (test_forms.py)
Test form validation:
- Field validation
- Form cleaning
- Custom validators
- Error messages
Running Tests by Marker
Use pytest markers to run specific test categories:Coverage Reporting
FootyCollect aims for high test coverage:1
Run tests with coverage
2
View HTML coverage report
3
Check coverage percentage
Look for the coverage summary in the terminal output:
Coverage Configuration
pyproject.toml
Migrations and test files are excluded from coverage reporting. Only application code is measured.
Test Database
Pytest uses a separate test database:Writing Tests
Using Fixtures
Common fixtures are defined infootycollect/conftest.py:
Test Example
test_models.py
Continuous Integration
Tests run automatically on GitHub Actions:- On every push and pull request
- Coverage reports uploaded to Codecov
- Must pass before merging
Next Steps
Code Quality
Code quality tools and linting
Project Structure
Understanding the codebase
Service Layer
Service layer architecture