Testing

This page explains how tests are configured and how to run them with pytest.

Configuration

  • Test runner: pytest
  • Django settings: pytest.ini sets DJANGO_SETTINGS_MODULE = config.settings.test
  • Test discovery:
  • python_files = tests.py test_*.py *_tests.py
  • testpaths includes: tests, idk/contracts, idk/crm, idk/reports, idk/clients, idk/activity, idk/alerts, idk/webhooks, idk/expenses, idk/users, idk/services, idk/notifications
  • Pytest options: ignores node_modules and src directories

See pytest.ini at the project root for the full configuration.

How to run

With pytest directly

pytest -v
  • Use -k to filter tests by keyword:
pytest -k notifications -v
  • Run a single test file or test:
pytest idk/notifications/tests/test_services.py::test_send_notification
  • Show slow tests and durations:
pytest -v --durations=10

Via Django manage.py

python manage.py test

With coverage

coverage run -m pytest -v
coverage report -m

The CI script also runs coverage via files/run-tests.sh.

Inside the Docker dev container

make ssh-local
pytest -v

Running tests with Docker (CI container)

You can run the same test container used in CI locally via Make:

make build
make test

Equivalent raw docker compose command:

docker compose run --rm idk-ci

Notes: - The CI container executes /app/files/run-tests.sh, which runs coverage + pytest with --ds=config.settings.test. - Ensure services (e.g., Postgres, Redis) are up if tests depend on them.

Useful tips

  • Markers/filters: use -m/-k to select subsets of tests
  • Stop on first failure: -x
  • Re-run failures first: --ff
  • Use pytest.ini to adjust defaults as needed

CI integration

  • GitHub Actions runs Django tests automatically (see django-tests.yml)
  • Coverage is collected and reported in CI
  • Failing tests will block merges by default