flakytest.dev anze3db fedidevs
All environments · last 30 days

Test suite performance

Suite wall time
38.32 s
avg over 12 profiled runs
Total test time
1m 40s
sum of test durations per run
Tests
315
in 1 environment
Failure rate
0.0%
1 of 4,279 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
1m 40s
Database Network Password hashing App code Factories Migrations Other (Libraries, DB schema, Templates, Mocking, ...)

Slowest tests

All tests →
Test and why it's slow Avg Share of suite Runs
accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
81% migrations · fixture django_db_setup (session scope) pytest_django/fixtures.py:186
7.28 s
7.3%
12
accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
81% migrations · test body accounts/tests.py:572
4.39 s
4.4%
12
confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
82% migrations · test body confs/tests.py:875
4.19 s
4.2%
12
confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
85% migrations · _post_teardown django/test/testcases.py:1243
3.96 s
4.0%
12
accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
82% migrations · fixture django_db_setup (session scope) pytest_django/fixtures.py:186
3.14 s
3.1%
12
confs/tests.py::TestMigratedLegacyConferences::test_fwd50_date_redirects
84% migrations · fixture django_db_setup (session scope) pytest_django/fixtures.py:186
3.03 s
3.0%
12
confs/tests.py::TestSyncAnnouncements::test_is_idempotent_and_refreshes_unposted_content
87% migrations · fixture django_db_setup (session scope) pytest_django/fixtures.py:186
2.98 s
3.0%
12
confs/tests.py::TestEditConference::test_edit_does_not_change_slug
92% password hashing · setUp confs/tests.py:1175
1.82 s
1.8%
12
confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
94% password hashing · setUp confs/tests.py:1175
1.82 s
1.8%
12
confs/tests.py::TestEditConference::test_other_user_forbidden
95% password hashing · setUp confs/tests.py:1175
1.70 s
1.7%
12

Fix next

From the latest run per environment, by time saved
1

Use a fast password hasher in tests

20.5s (30% of test time) is spent hashing passwords. Slow hashing protects real passwords; in tests it only burns CPU.

High Password hashing ci:github-actions:test
19.50 s per run
Fix: In your test settings set PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] (currently PBKDF2PasswordHasher). Read the guide
Details

Only change the hasher in test settings. Tests that assert on a specific hash format need updating.

Where:

  • confs/tests.py:1044 TestCreateConference.setUp · 4.14 s
  • confs/tests.py:1175 TestEditConference.setUp · 2.81 s
  • confs/tests.py:1177 TestEditConference.setUp · 2.63 s
  • confs/tests.py:1176 TestEditConference.setUp · 2.58 s
  • confs/tests.py:1371 TestApproveConference.setUp · 2.09 s
  • confs/tests.py:1372 TestApproveConference.setUp · 2.05 s
  • confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.23 s
  • confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 1.23 s
  • confs/tests.py:1296 TestUnapproveConference.setUp · 498 ms
  • confs/tests.py:1295 TestUnapproveConference.setUp · 496 ms

Most affected tests:

  • confs/tests.py::TestEditConference::test_other_user_forbidden
  • confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
  • confs/tests.py::TestEditConference::test_edit_does_not_change_slug
  • confs/tests.py::TestApproveConference::test_get_not_allowed
  • confs/tests.py::TestEditConference::test_owner_can_edit
  • confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
  • confs/tests.py::TestApproveConference::test_staff_sees_approve_button_on_detail
  • fedidevs/tests.py::TestAnonymousCacheAndCsrf::test_authenticated_html_is_private_and_keeps_csrf_header

Documentation

2

Use plain static file storage in tests

Static file storage/manifest handling costs 16.0s.

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

Where:

  • accounts/views.py:425 index · 681 ms
  • starter_packs/tests.py:841 TestShareStarterPack.test_api_formats · 450 ms
  • confs/tests.py:875 TestConferencePage.test_conference_with_utc_with_date_no_posts · 362 ms
  • starter_packs/views.py:862 share_starter_pack · 324 ms
  • starter_packs/tests.py:125 TestCreateStarterPack.test_form_error · 275 ms
  • accounts/tests.py:550 TestAccountIndexRobots.assert_noindex · 272 ms
  • starter_packs/tests.py:1027 TestPinAccountInStarterPack.test_pin_button_shown_on_review_page · 269 ms
  • confs/views.py:296 _conference_detail · 256 ms
  • starter_packs/tests.py:709 TestShareStarterPack.test_logged_in · 225 ms
  • starter_packs/tests.py:781 TestShareStarterPack.test_order_by · 214 ms

Most affected tests:

  • confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
  • starter_packs/tests.py::TestPinAccountInStarterPack::test_pin_button_shown_on_review_page
  • starter_packs/tests.py::TestCreateStarterPack::test_form_error
  • accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
  • starter_packs/tests.py::TestShareStarterPack::test_logged_in
  • accounts/tests.py::TestStaticPages::test_developers_on_mastodon
  • confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_date_redirects
  • starter_packs/tests.py::TestEditStarterPackAccounts::test_not_logged_in
3

Stop re-running migrations on every test run

Migrations take 16.9s per run, before the first test can start.

High Migrations ci:github-actions:test
15.22 s per run
Fix: Run with --reuse-db (add it to addopts in pytest.ini/pyproject) so the test database survives between runs; pass --create-db when migrations change. If no test depends on data migrations, --nomigrations builds the schema straight from the models, which is faster still. Read the guide
Details

CI should still build the database from scratch (no --reuse-db) so broken migrations are caught.

Where:

  • confs/tests.py:432 TestLegacyConferenceDataMigration._migrate · 938 ms
  • confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 449 ms
  • fedidevs/db/postgresql/base.py:39 DatabaseWrapper.get_new_connection · 141 ms
  • confs/migrations/0033_remove_legacy_conference_tables.py:388 _get_or_create_conference · 102 ms
  • confs/tests.py:412 TestLegacyConferenceDataMigration._leaf_targets · 61 ms
  • confs/tests.py:431 TestLegacyConferenceDataMigration._migrate · 55 ms
  • confs/migrations/0033_remove_legacy_conference_tables.py:214 _pk_batches · 54 ms
  • confs/migrations/0033_remove_legacy_conference_tables.py:398 migrate_legacy_pair · 42 ms
  • confs/migrations/0011_conferencepost_alter_conference_posts.py:11 update · 41 ms
  • confs/tests.py:430 TestLegacyConferenceDataMigration._migrate · 39 ms

Most affected tests:

  • confs/tests.py::TestSyncAnnouncements::test_is_idempotent_and_refreshes_unposted_content
  • accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
  • confs/tests.py::TestMigratedLegacyConferences::test_fwd50_date_redirects
  • accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
  • confs/tests.py::TestLegacyConferenceDataMigration::test_copies_overlapping_legacy_rows_without_clobbering_existing_data
  • confs/tests.py::TestLegacyConferenceDataMigration::test_drops_legacy_tables_when_uniques_are_mysql_style_indexes

Documentation

4

Run migrations once, not once per worker

Each of the 4 pytest-xdist workers builds its own test database by running every migration: 19.5s in total, about 4.9s per worker. 14.6s of it repeats work another worker already did.

Medium Migrations ci:github-actions:test
14.64 s per run
Fix: Migrate once and copy the database: let one worker build the test database and have the others create theirs from it as a template (on PostgreSQL, CREATE DATABASE ... TEMPLATE ..., which copies files instead of running migrations). Django's own test runner already does this with --parallel. Read the guide
Details

Every copy is built by the same migrations, so a broken migration still fails the run.

  • {'total': 19.52, 'builds': 4, 'workers': 4, 'per_build': 4.88}

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

1 regression caught
Test Verdict CI fails Local fails Fail rate Last failure
starter_packs/tests.py::TestShareStarterPack::test_api_plain_json Regression caught 1/14 0/0 7% 3 weeks, 6 days ago
Flaky: failed and passed on the same commit. Regression caught: fixed by a change outside the test file. Test changed: fixed by editing the test. All failing tests →

Environments

Every CI job and developer machine that reported in the last 30 days
Environment Profiled runs Sessions Avg wall time Peak memory Last seen
CI github-actions:test 12 14 38.32 s 679 MB 10 hours ago
CI github-actions 0 0 – – 4 months, 3 weeks ago