Passed Run of Oct 20, 18:20
Where the time goes
Test time by category- Password hashing27.83 s
- Migrations21.18 s
- Libraries15.03 s
- Database10.15 s
- DB schema4.32 s
- Templates2.21 s
- Mocking1.67 s
- Imports1.56 s
- Factories434 ms
- pytest405 ms
- Unsampled193 ms
- Deep copies67 ms
- App code52 ms
- Network30 ms
- Logging26 ms
- Waiting26 ms
- Cache25 ms
- Test code17 ms
- Serialization10 ms
Session timeline
Fix next
Ranked by the time each fix saves per runUse a fast password hasher in tests
27.8s (33% of test time) is spent hashing passwords. Slow hashing protects real passwords; in tests it only burns CPU.
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.85 s
- confs/tests.py:1175 TestEditConference.setUp · 3.92 s
- confs/tests.py:1176 TestEditConference.setUp · 3.91 s
- confs/tests.py:1177 TestEditConference.setUp · 3.79 s
- confs/tests.py:1371 TestApproveConference.setUp · 2.63 s
- confs/tests.py:1372 TestApproveConference.setUp · 2.55 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 2.06 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.96 s
- confs/tests.py:1295 TestUnapproveConference.setUp · 634 ms
- confs/tests.py:1296 TestUnapproveConference.setUp · 626 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestEditConference::test_owner_sees_edit_button_on_approved_detail
- confs/tests.py::TestEditConference::test_requires_login
Use plain static file storage in tests
Static file storage/manifest handling costs 22.5s.
Details
Where:
- accounts/views.py:425 index · 872 ms
- confs/views.py:296 _conference_detail · 725 ms
- starter_packs/tests.py:841 TestShareStarterPack.test_api_formats · 562 ms
- accounts/tests.py:550 TestAccountIndexRobots.assert_noindex · 518 ms
- starter_packs/tests.py:781 TestShareStarterPack.test_order_by · 460 ms
- starter_packs/views.py:862 share_starter_pack · 456 ms
- confs/tests.py:152 TestMigratedLegacyConferences._assert_no_naive_warning · 367 ms
- fedidevs/tests.py:33 TestAccountIndexQueryParams.test_empty_q_is_preserved · 328 ms
- confs/tests.py:1100 TestCreateConference.test_rejects_end_date_before_start · 321 ms
- starter_packs/tests.py:37 TestStarterPacks.test_index_page_logged_in · 309 ms
Most affected tests:
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestCreateConference::test_rejects_end_date_before_start
- fedidevs/tests.py::TestAccountIndexQueryParams::test_empty_q_is_preserved
- starter_packs/tests.py::TestStarterPacks::test_index_page_logged_in
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconafrica_page
- starter_packs/tests.py::TestRemoteFollowStarterPack::test_mastodon_handle_is_told_to_log_in
Stop re-running migrations on every test run
Migrations take 21.2s per run, before the first test can start.
Details
CI should still build the database from scratch (no --reuse-db) so broken migrations are caught.
Where:
- confs/tests.py:432 TestLegacyConferenceDataMigration._migrate · 1.15 s
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 577 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:388 _get_or_create_conference · 104 ms
- confs/tests.py:412 TestLegacyConferenceDataMigration._leaf_targets · 94 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:214 _pk_batches · 88 ms
- confs/tests.py:430 TestLegacyConferenceDataMigration._migrate · 73 ms
- confs/tests.py:431 TestLegacyConferenceDataMigration._migrate · 67 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:398 migrate_legacy_pair · 44 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:325 _refresh_account_counts · 41 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:358 _attach_lookups_and_tags · 38 ms
Most affected tests:
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_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
Create shared test data in setUpTestData instead of setUp
setUp() runs before every test and takes 27.2s in total (password hashing 26.9s, db 211ms, factories 15ms) in 7 classes: TestCreateConference (10 tests), TestEditConference (9 tests), TestUnapproveConference (2 tests), TestConferenceApprovalVisibility (5 tests).
Details
Since Django 3.2 attributes assigned in setUpTestData are deep-copied per test, so in-memory changes don't leak between tests. Keep objects a test modifies in the database (or re-fetches) as before.
Where:
- confs/tests.py:1044 TestCreateConference.setUp · 4.87 s
- confs/tests.py:1175 TestEditConference.setUp · 3.94 s
- confs/tests.py:1176 TestEditConference.setUp · 3.92 s
- confs/tests.py:1177 TestEditConference.setUp · 3.80 s
- confs/tests.py:1371 TestApproveConference.setUp · 2.64 s
- confs/tests.py:1372 TestApproveConference.setUp · 2.56 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 2.07 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.97 s
- confs/tests.py:1295 TestUnapproveConference.setUp · 637 ms
- confs/tests.py:1296 TestUnapproveConference.setUp · 628 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestEditConference::test_owner_sees_edit_button_on_approved_detail
- confs/tests.py::TestEditConference::test_requires_login
Repeated queries (N+1) in the code under test
10 tests run the same query 10+ times, e.g. 45x in test_djangoconus_old_url_redirects. N+1 queries slow the tests and production alike.
Details
This changes application code, so it speeds up production too; the tests stay as they are.
- 45x in test_djangoconus_old_url_redirects: SELECT "confs_conferencetag"."id", "confs_conferencetag"."name", "confs_conferencetag"."slug", "confs_conferencetag"."icon" FROM "confs_conferencetag" WHERE "confs_conferencetag"."slug" = %s LIMIT ? FOR UPDATE
- 45x in test_single_facet_is_indexable: SELECT "confs_conferencetag"."id", "confs_conferencetag"."name", "confs_conferencetag"."slug", "confs_conferencetag"."icon" FROM "confs_conferencetag" WHERE "confs_conferencetag"."slug" = %s LIMIT ? FOR UPDATE
- 45x in test_invalid_selected_instance: SELECT "confs_conferencetag"."id", "confs_conferencetag"."name", "confs_conferencetag"."slug", "confs_conferencetag"."icon" FROM "confs_conferencetag" WHERE "confs_conferencetag"."slug" = %s LIMIT ? FOR UPDATE
- 45x in test_conference_with_utc_with_date_no_posts: SELECT "confs_conferencetag"."id", "confs_conferencetag"."name", "confs_conferencetag"."slug", "confs_conferencetag"."icon" FROM "confs_conferencetag" WHERE "confs_conferencetag"."slug" = %s LIMIT ? FOR UPDATE
- 44x in test_posts_from_yesterday_are_updated: SELECT COUNT(*) AS "__count" FROM "accounts_accountlookup" WHERE UPPER("accounts_accountlookup"."language"::text) LIKE UPPER(%s)
Most affected tests:
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- stats/tests.py::TestStats::test_posts_from_yesterday_are_updated
- stats/tests.py::TestStats::test_store_daily_stats
- stats/tests.py::TestStats::test_store_daily_stats_with_accounts
- accounts/tests.py::TestInstanceIndexingBridgy::test_follows_redirect_and_coerces_null_version
Disable django-debug-toolbar in tests
django-debug-toolbar is installed in the test settings and costs 8.5s.
Details
Where:
- accounts/views.py:425 index · 872 ms
- confs/views.py:296 _conference_detail · 725 ms
- starter_packs/views.py:862 share_starter_pack · 456 ms
- accounts/templatetags/account_extras.py:34 instances_datalist · 254 ms
- accounts/views.py:28 CountlessPage.__init__ · 229 ms
- confs/views.py:128 conferences · 188 ms
- starter_packs/views.py:858 share_starter_pack · 181 ms
- starter_packs/views.py:60 get_editable_pack · 148 ms
- accounts/views.py:295 index · 143 ms
- accounts/templatetags/account_extras.py:36 instances_datalist · 138 ms
Most affected tests:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconafrica_page
- confs/tests.py::TestMigratedLegacyConferences::test_dotnetconf_page
- accounts/tests.py::TestSelectedInstance::test_selected_instance_through_session
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestMigratedLegacyConferences::test_migrated_conference_shows_linked_posts
Make the test database server skip durability work
Tests spend 35.6s (42%) in the database. Test databases don't need to survive a crash, so the server can skip flushing to disk.
Details
Only affects crash safety of the throwaway test server; query behaviour is identical.
Where:
- confs/tests.py:432 TestLegacyConferenceDataMigration._migrate · 1.15 s
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 577 ms
- starter_packs/tests.py:397 TestToggleStarterPackAccount.test_toggle_after_limit · 545 ms
- accounts/templatetags/account_extras.py:34 instances_datalist · 254 ms
- accounts/views.py:28 CountlessPage.__init__ · 229 ms
- stats/models.py:20 store_daily_stats · 211 ms
- starter_packs/views.py:862 share_starter_pack · 197 ms
- starter_packs/views.py:858 share_starter_pack · 181 ms
- starter_packs/views.py:60 get_editable_pack · 148 ms
- accounts/views.py:295 index · 143 ms
Most affected tests:
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_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
- starter_packs/tests.py::TestToggleStarterPackAccount::test_toggle_after_limit
- mastodon_auth/tests.py::RegisterAppTests::test_returns_credentials_on_200
pytest takes a long time before the first test runs
Startup takes 7.7s and collection 2.9s on every run, even when you only run one test.
Details
- mastodon_auth/tests.py (1.2s)
- starter_packs/tests.py (365ms)
- accounts/tests.py (53ms)
- confs/tests.py (19ms)
- fedidevs/tests.py (4ms)
- fedidevs/settings.py (1.8s)
- debug_toolbar/panels/sql/__init__.py (960ms)
- starter_packs/admin.py (785ms)
Run migrations once, not once per worker
Each of the 4 pytest-xdist workers builds its own test database by running every migration: 23.1s in total, about 5.8s per worker. 17.4s of it repeats work another worker already did.
Details
Every copy is built by the same migrations, so a broken migration still fails the run.
- {'total': 23.137, 'builds': 4, 'workers': 4, 'per_build': 5.784}
Tests
1–200 of 301, slowest first · click a column to sort this pageMemory
Busiest worker peaked at 210 MB; all 4 together at about 678 MB| Worker | Tests | Peak | Grew by |
|---|---|---|---|
| gw0 | 33 | 178 MB | 35 MB |
| gw1 | 93 | 206 MB | 60 MB |
| gw2 | 143 | 195 MB | 52 MB |
| gw3 | 32 | 210 MB | 35 MB |
Slowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 70 | 23.17 s |
| django_db_setup | session | 4 | 23.14 s |
| _unittest_setUpClass_fixture_TestSelectedInstance | class | 1 | 169 ms |
| _unittest_setUpClass_fixture_TestConferencePage | class | 2 | 134 ms |
| _unittest_setUpClass_fixture_TestShareStarterPack | class | 2 | 119 ms |
| _unittest_setUpClass_fixture_TestPinAccountInStarterPack | class | 2 | 105 ms |
| _unittest_setUpClass_fixture_TestWebfingerBackfill | class | 1 | 87 ms |
| _unittest_setUpClass_fixture_TestOwnerManagement | class | 2 | 85 ms |
| _unittest_setUpClass_fixture_TestFollowStarterPack | class | 2 | 73 ms |
| _unittest_setUpClass_fixture_TestCreateStarterPack | class | 2 | 57 ms |
| _unittest_setUpClass_fixture_TestFollowBg | class | 1 | 55 ms |
| _unittest_setUpClass_fixture_TestRemoteFollowStarterPack | class | 2 | 45 ms |
| _unittest_setUpClass_fixture_TestAddAccountsSearch | class | 1 | 41 ms |
| _unittest_setUpClass_fixture_TestStarterPacks | class | 1 | 39 ms |
| _unittest_setUpClass_fixture_TestDeleteStarterPack | class | 1 | 38 ms |