Skip to content

Testing

Dave Lawrence edited this page Jul 30, 2026 · 2 revisions

Unit Testing

Tests extend django.test.TestCase. There are a lot of migrations in the project, so use --keepdb to reuse the test database and save a lot of time:

python3 manage.py test --keepdb

# A specific module / class / method
python3 manage.py test --keepdb snpdb.tests.test_variant
python3 manage.py test --keepdb snpdb.tests.test_variant.VariantTest.test_something

UNIT_TEST is set in default_settings.py (sys.argv[1:2] == ['test']) and used to skip expensive setup during tests.

URL tests

URL tests use URLTestCase from library/django_utils/unittest_utils.py, which overrides settings for static files, disables Celery async and disables annotation caching, and provides _test_urls() for batch URL status code testing.

Each app has a test_urls.py covering its views and grids — this is also where you check that private data raises PermissionDenied for users without permission (see Users, permissions and groups).

Fixture / fake data

Helpers for building test data live in:

  • annotation/tests/test_data_fake_genes.py — fake genes/transcripts
  • snpdb/tests/utils/ — variants, VCFs, cohorts etc
  • annotation/tests/test_data/ — VEP-annotated VCFs per columns version, used by annotation.tests.test_annotation_vcf (see Variant Annotation - adding new columns)

Linting

See Developer Setup and Tips.

Clone this wiki locally