Skip to main content
FootyCollect uses pytest for testing with comprehensive coverage reporting. Tests are organized by app and functionality.

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

Test Django models:
  • Model creation and validation
  • Field constraints
  • Model methods
  • Relationships
Test Django views:
  • URL resolution
  • View responses
  • Form handling
  • Permission checks
Test business logic in the service layer:
  • Service methods
  • Business rules
  • Data transformations
  • Error handling
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

Coverage is automatically collected (configured in pytest.ini)
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:
The --reuse-db and --nomigrations flags are set by default in pytest.ini for faster test runs. The database is created from models, not migrations.

Writing Tests

Using Fixtures

Common fixtures are defined in footycollect/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
See the project README for CI configuration.

Next Steps

Code Quality

Code quality tools and linting

Project Structure

Understanding the codebase

Service Layer

Service layer architecture