Passed Run of Oct 22, 22:27
Where the time goes
Test time by category- Password hashing29.50 s
- Migrations23.62 s
- Libraries17.72 s
- Database9.82 s
- DB schema2.90 s
- Templates1.92 s
- Imports1.60 s
- Mocking1.45 s
- pytest436 ms
- Factories416 ms
- Unsampled207 ms
- App code85 ms
- Deep copies62 ms
- Waiting20 ms
- Test code18 ms
- Cache18 ms
- Network16 ms
- Logging8 ms
- Serialization6 ms
Session timeline
Fix next
Ranked by the time each fix saves per runUse a fast password hasher in tests
29.5s (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 · 5.54 s
- confs/tests.py:1176 TestEditConference.setUp · 3.68 s
- confs/tests.py:1175 TestEditConference.setUp · 3.66 s
- confs/tests.py:1177 TestEditConference.setUp · 3.60 s
- confs/tests.py:1371 TestApproveConference.setUp · 2.93 s
- confs/tests.py:1372 TestApproveConference.setUp · 2.93 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 2.60 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 2.24 s
- fedidevs/tests.py:63 TestAnonymousCacheAndCsrf.test_authenticated_html_is_private_and_keeps_csrf_header · 642 ms
- confs/tests.py:1296 TestUnapproveConference.setUp · 602 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestConferenceApprovalVisibility::test_other_user_does_not_see_pending
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestConferenceApprovalVisibility::test_owner_sees_own_pending
- fedidevs/tests.py::TestAnonymousCacheAndCsrf::test_authenticated_html_is_private_and_keeps_csrf_header
Use plain static file storage in tests
Static file storage/manifest handling costs 23.9s.
Details
Where:
- accounts/views.py:425 index · 770 ms
- starter_packs/tests.py:841 TestShareStarterPack.test_api_formats · 701 ms
- accounts/tests.py:550 TestAccountIndexRobots.assert_noindex · 666 ms
- confs/tests.py:152 TestMigratedLegacyConferences._assert_no_naive_warning · 611 ms
- confs/views.py:296 _conference_detail · 470 ms
- starter_packs/views.py:862 share_starter_pack · 399 ms
- starter_packs/tests.py:781 TestShareStarterPack.test_order_by · 398 ms
- accounts/tests.py:555 TestAccountIndexRobots.assert_indexable · 327 ms
- starter_packs/tests.py:60 TestStarterPacks.test_index_page_language_filter · 268 ms
- accounts/tests.py:536 TestStaticPages.test_developers_on_mastodon · 264 ms
Most affected tests:
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconafrica_page
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- starter_packs/tests.py::TestStarterPacks::test_index_page_language_filter
- confs/tests.py::TestConferencePage::test_conference_with_pacific_with_date
- starter_packs/tests.py::TestShareStarterPack::test_api_formats_7___text_plain____text_html__
- accounts/tests.py::TestStaticPages::test_developers_on_mastodon
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
Stop re-running migrations on every test run
Migrations take 23.6s 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.31 s
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 687 ms
- confs/tests.py:412 TestLegacyConferenceDataMigration._leaf_targets · 156 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:388 _get_or_create_conference · 115 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:214 _pk_batches · 98 ms
- confs/tests.py:430 TestLegacyConferenceDataMigration._migrate · 70 ms
- confs/tests.py:431 TestLegacyConferenceDataMigration._migrate · 65 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:398 migrate_legacy_pair · 62 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:325 _refresh_account_counts · 51 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:358 _attach_lookups_and_tags · 39 ms
Most affected tests:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- 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 28.6s in total (password hashing 28.4s, db 208ms, factories 10ms) in 7 classes: TestFollowStarterPack (3 tests), TestPostAnnouncements (6 tests), TestConferenceApprovalVisibility (5 tests), TestApproveConference (6 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 · 5.56 s
- confs/tests.py:1176 TestEditConference.setUp · 3.69 s
- confs/tests.py:1175 TestEditConference.setUp · 3.66 s
- confs/tests.py:1177 TestEditConference.setUp · 3.62 s
- confs/tests.py:1371 TestApproveConference.setUp · 2.95 s
- confs/tests.py:1372 TestApproveConference.setUp · 2.94 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 2.61 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 2.25 s
- confs/tests.py:1296 TestUnapproveConference.setUp · 604 ms
- confs/tests.py:1295 TestUnapproveConference.setUp · 603 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestConferenceApprovalVisibility::test_other_user_does_not_see_pending
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestConferenceApprovalVisibility::test_owner_sees_own_pending
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
Repeated queries (N+1) in the code under test
10 tests run the same query 10+ times, e.g. 45x in test_invalid_selected_instance. 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_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_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_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_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:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
- 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
- confs/tests.py::TestLegacyConferenceDataMigration::test_copies_overlapping_legacy_rows_without_clobbering_existing_data
Disable django-debug-toolbar in tests
django-debug-toolbar is installed in the test settings and costs 8.0s.
Details
Where:
- accounts/views.py:425 index · 770 ms
- confs/views.py:296 _conference_detail · 470 ms
- starter_packs/views.py:862 share_starter_pack · 399 ms
- confs/views.py:128 conferences · 199 ms
- starter_packs/views.py:858 share_starter_pack · 182 ms
- starter_packs/views.py:185 starter_packs · 165 ms
- starter_packs/views.py:60 get_editable_pack · 165 ms
- accounts/templatetags/account_extras.py:36 instances_datalist · 157 ms
- accounts/views.py:28 CountlessPage.__init__ · 152 ms
- confs/views.py:509 create_conference · 137 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
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- fedidevs/tests.py::TestAnonymousCacheAndCsrf::test_other_pages_keep_unknown_query_params
- confs/tests.py::TestMigratedLegacyConferences::test_dotnetconf_page
- accounts/tests.py::TestSelectedInstance::test_selected_instance_through_session
- fedidevs/tests.py::TestAnonymousCacheAndCsrf::test_anonymous_forms_work_after_csrf_bootstrap
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconafrica_page
Make the test database server skip durability work
Tests spend 36.3s (40%) 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.31 s
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 687 ms
- starter_packs/tests.py:397 TestToggleStarterPackAccount.test_toggle_after_limit · 644 ms
- starter_packs/views.py:862 share_starter_pack · 191 ms
- starter_packs/views.py:858 share_starter_pack · 181 ms
- stats/models.py:20 store_daily_stats · 177 ms
- starter_packs/views.py:60 get_editable_pack · 165 ms
- accounts/templatetags/account_extras.py:36 instances_datalist · 157 ms
- confs/tests.py:412 TestLegacyConferenceDataMigration._leaf_targets · 156 ms
- accounts/views.py:28 CountlessPage.__init__ · 152 ms
Most affected tests:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- 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
- accounts/tests.py::TestInstanceIndexingBridgy::test_follows_redirect_and_coerces_null_version
pytest takes a long time before the first test runs
Startup takes 7.8s and collection 3.0s on every run, even when you only run one test.
Details
- mastodon_auth/tests.py (1.3s)
- starter_packs/tests.py (374ms)
- accounts/tests.py (66ms)
- confs/tests.py (28ms)
- announcements/tests.py (2ms)
- fedidevs/settings.py (2.1s)
- debug_toolbar/panels/sql/__init__.py (1.2s)
- starter_packs/admin.py (806ms)
pytest-xdist workers finish at very different times
The busiest worker ran 27.6s of tests, the least busy 20.3s.
Details
Run migrations once, not once per worker
Each of the 4 pytest-xdist workers builds its own test database by running every migration: 24.2s in total, about 6.1s per worker. 18.2s 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': 24.222, 'builds': 4, 'workers': 4, 'per_build': 6.055}
Tests
1–200 of 302, slowest first · click a column to sort this pageMemory
Busiest worker peaked at 208 MB; all 4 together at about 672 MB| Worker | Tests | Peak | Grew by |
|---|---|---|---|
| gw0 | 91 | 191 MB | 49 MB |
| gw1 | 146 | 201 MB | 58 MB |
| gw2 | 32 | 208 MB | 32 MB |
| gw3 | 33 | 179 MB | 38 MB |
Slowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 70 | 24.26 s |
| django_db_setup | session | 4 | 24.22 s |
| _unittest_setUpClass_fixture_TestSelectedInstance | class | 1 | 162 ms |
| _unittest_setUpClass_fixture_TestConferencePage | class | 2 | 127 ms |
| _unittest_setUpClass_fixture_TestShareStarterPack | class | 2 | 125 ms |
| _unittest_setUpClass_fixture_TestPinAccountInStarterPack | class | 2 | 85 ms |
| _unittest_setUpClass_fixture_TestOwnerManagement | class | 2 | 81 ms |
| _unittest_setUpClass_fixture_TestFollowStarterPack | class | 2 | 76 ms |
| _unittest_setUpClass_fixture_TestWebfingerBackfill | class | 1 | 60 ms |
| _unittest_setUpClass_fixture_TestToggleStarterPackAccount | class | 1 | 46 ms |
| _unittest_setUpClass_fixture_TestRemoteFollowStarterPack | class | 2 | 45 ms |
| _unittest_setUpClass_fixture_TestFollowBg | class | 1 | 45 ms |
| _unittest_setUpClass_fixture_TestStarterPacks | class | 1 | 40 ms |
| _unittest_setUpClass_fixture_TestAddAccountsSearch | class | 1 | 40 ms |
| _unittest_setUpClass_fixture_TestEditStarterPackAccounts | class | 1 | 38 ms |