flakytest.dev anze3db flakytest
ci:github-actions:test · last 1 day

Test suite performance

Suite wall time
31.01 s
avg over 5 profiled runs
Total test time
25.45 s
sum of test durations per run
Tests
235
in 1 environment
Failure rate
0.0%
0 of 1,164 results
Flaky tests
0

Suite wall time per run

Click a point to open the run

Where the time goes

Avg test time per run
CI github-actions:test
25.45 s
Database Test code Password hashing App code Factories Migrations Other (Libraries, DB schema, Imports, Templates, ...)

Slowest tests

All tests →
Test and why it's slow Avg Share of suite Runs
apps/api/tests.py::TestApiIndex::test_index
77% migrations · fixture django_db_setup (session scope) pytest_django/fixtures.py:198
3.87 s
15.2%
5
apps/projects/tests.py::SeedDemoCommandTest::test_seed_demo
64% database · test body apps/projects/tests.py:1143
1.93 s
7.6%
5
ft/tests.py::TestAccountSettings::test_change_password
97% password hashing · test body ft/tests.py:203
1.13 s
4.4%
5
apps/projects/tests.py::ProfilePagePaginationTest::test_slowest_tests_first_then_the_next_page
68% database · setUpClass django/test/testcases.py:1439
391 ms
1.5%
5
apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
68% password hashing · test body apps/orgs/tests.py:28
379 ms
1.5%
5
apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
59% database · test body apps/api/tests.py:285
370 ms
1.5%
5
apps/projects/tests.py::ProjectPagesTest::test_configure_page
73% database · setUpClass django/test/testcases.py:1439
362 ms
1.4%
5
apps/api/tests.py::ProfileUploadTest::test_missing_parts_mark_the_profile_incomplete
40% database · test body apps/api/tests.py:830
313 ms
1.2%
5
apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
47% db schema · test body apps/api/tests.py:246
311 ms
1.2%
5
apps/orgs/tests.py::SuperuserTest::test_superusers_can_open_any_project_but_dont_list_them
76% password hashing · test body apps/orgs/tests.py:194
305 ms
1.2%
5

Fix next

From the latest run per environment, by time saved
1

Run tests in parallel on all 2 CPUs

Tests run one at a time: 26.1s of test time on a 2-CPU machine. With pytest-xdist this could take about 13.1s.

High Parallelism ci:github-actions:test
13.05 s per run
Fix: pip install pytest-xdist, then run pytest -n auto (add it to addopts, or only in CI). pytest-django creates a separate test database per worker automatically.
Details

Tests must not share state: files in fixed paths, ports, a shared database without per-worker names, or module globals. Run with -p randomly first to shake out order dependencies.

Documentation

2

Use plain static file storage in tests

Static file storage/manifest handling costs 11.1s.

High App code ci:github-actions:test
11.14 s per run
Fix: In test settings use STORAGES["staticfiles"] = {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"} so templates don't need a manifest.
Details

Where:

  • apps/mcp/tests.py:66 McpTest.post · 577 ms
  • apps/api/tests.py:487 ProfileUploadTest.upload · 552 ms
  • ft/tests.py:203 TestAccountSettings.test_change_password · 413 ms
  • apps/orgs/tests.py:28 SignupTest.test_signing_up_creates_an_organization · 289 ms
  • ft/tests.py:159 TestAccountPages.test_signup · 250 ms
  • apps/projects/urls.py:498 project_profile · 212 ms
  • ft/tests.py:198 TestAccountSettings.test_change_password · 205 ms
  • ft/tests.py:96 TestTrubleshootingPage.test_troubleshooting · 200 ms
  • apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 186 ms
  • apps/api/tests.py:352 IngestEnvironmentTest.ingest_start · 181 ms

Most affected tests:

  • ft/tests.py::TestAccountSettings::test_change_password
  • apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
  • apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
  • ft/tests.py::TestAccountPages::test_signup
  • apps/api/tests.py::ProfileUploadTest::test_missing_parts_mark_the_profile_incomplete
  • ft/tests.py::TestTrubleshootingPage::test_troubleshooting
  • apps/projects/tests.py::IndexPageTest::test_index_page
  • apps/api/tests.py::ProfileUploadTest::test_upload_links_ingest_session
3

Disable django-debug-toolbar in tests

django-debug-toolbar is installed in the test settings and costs 6.4s.

High App code ci:github-actions:test
6.42 s per run
Fix: Only add debug_toolbar to INSTALLED_APPS and MIDDLEWARE when not testing (e.g. `if DEBUG and not TESTING:`).
Details

Where:

  • ft/tests.py:203 TestAccountSettings.test_change_password · 413 ms
  • apps/orgs/tests.py:28 SignupTest.test_signing_up_creates_an_organization · 275 ms
  • ft/tests.py:159 TestAccountPages.test_signup · 250 ms
  • apps/projects/urls.py:498 project_profile · 212 ms
  • ft/tests.py:198 TestAccountSettings.test_change_password · 205 ms
  • apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 186 ms
  • apps/projects/tests.py:88 IndexPageTest.test_index_page · 146 ms
  • apps/orgs/views.py:33 org_shell · 137 ms
  • apps/orgs/models.py:65 Organization.is_owner · 119 ms
  • apps/projects/urls.py:40 can_manage_project · 119 ms

Most affected tests:

  • ft/tests.py::TestAccountSettings::test_change_password
  • apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
  • apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
  • ft/tests.py::TestAccountPages::test_signup
  • apps/api/tests.py::ProfileUploadTest::test_missing_parts_mark_the_profile_incomplete
  • apps/projects/tests.py::IndexPageTest::test_index_page
  • apps/projects/tests.py::ProfilePagePaginationTest::test_slowest_tests_first_then_the_next_page
  • apps/projects/tests.py::ProjectPagesTest::test_projects_page

Documentation

4

Repeated queries (N+1) in the code under test

27 tests run the same query 10+ times, e.g. 180x in test_seed_demo. N+1 queries slow the tests and production alike.

High Database ci:github-actions:test
3.34 s per run
Fix: Django: fetch related rows in one query with select_related() for foreign keys and prefetch_related() for reverse/many-to-many relations, then lock the count in with assertNumQueries (or pytest-django's django_assert_num_queries).
Details

This changes application code, so it speeds up production too; the tests stay as they are.

  • 180x in test_seed_demo: SELECT "projects_test"."id", "projects_test"."name", "projects_test"."project_id", "projects_test"."slug", "projects_test"."date_last_run", "projects_test"."date_first_seen", "projects_test"."first_commit_id", "projects_test"."muted" FROM "projects_test" WHERE ("projects_test"."name" = %s AND "proj…
  • 22x in test_dashboard_filters: SELECT "projects_environment"."id", "projects_environment"."project_id", "projects_environment"."name", "projects_environment"."kind", "projects_environment"."provider", "projects_environment"."details", "projects_environment"."date_first_seen", "projects_environment"."date_last_seen" FROM "project…
  • 21x in test_configure_page: SELECT "projects_profile"."id", "projects_profile"."project_id", "projects_profile"."number", "projects_profile"."environment_id", "projects_profile"."session_id", "projects_profile"."run_id", "projects_profile"."commit_id", "projects_profile"."ingest_id", "projects_profile"."external_id", "project…
  • 20x in test_index: SELECT "django_content_type"."model" AS "model" FROM "django_content_type" WHERE "django_content_type"."app_label" = %s
  • 20x in test_daily_stats_count_a_profile_once_every_part_is_in: SELECT "projects_profilepart"."id", "projects_profilepart"."profile_id", "projects_profilepart"."index", "projects_profilepart"."count", "projects_profilepart"."checksum", "projects_profilepart"."status", "projects_profilepart"."error", "projects_profilepart"."tests_count", "projects_profilepart"."…

Most affected tests:

  • apps/projects/tests.py::SeedDemoCommandTest::test_seed_demo
  • apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
  • apps/projects/tests.py::ProjectPagesTest::test_configure_page
  • apps/api/tests.py::TestApiIndex::test_index
  • apps/api/tests.py::ProfileUploadTest::test_daily_stats_count_a_profile_once_every_part_is_in
  • apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
  • apps/api/tests.py::IngestStartEndpointTest::test_details_are_kept_for_failures_only
  • apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress

Documentation

CI vs local

Tests that are much slower in CI, and why

Upload profiles from CI and from a developer machine to compare them.

Locally: FLAKYTEST_SECRET_TOKEN=… pytest --flakytest-profile

Failing and flaky tests

No failures in this window.

Environments

Every CI job and developer machine that reported in the last 1 days
Environment Profiled runs Sessions Avg wall time Peak memory Last seen
CI github-actions:test 5 5 31.01 s 173 MB 18 minutes ago
CI github-actions 0 0 – – 2 years ago