Passed Run of Nov 14, 10:21
pytest --flakytest-profile --flakytest-rate 2000.
Where the time goes
Test time by category- Password hashing20.53 s
- Migrations16.92 s
- Libraries11.43 s
- Database9.96 s
- DB schema5.24 s
- Templates1.38 s
- Imports1.00 s
- Mocking996 ms
- pytest418 ms
- Unsampled361 ms
- Factories274 ms
- App code96 ms
- Deep copies64 ms
- Waiting23 ms
- Network14 ms
- Test code13 ms
- Logging10 ms
- Cache9 ms
- Serialization5 ms
- Fixture loading2 ms
Session timeline
Fix next
Ranked by the time each fix saves per runUse 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.
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
Use plain static file storage in tests
Static file storage/manifest handling costs 16.0s.
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
Stop re-running migrations on every test run
Migrations take 16.9s 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 · 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
Create shared test data in setUpTestData instead of setUp
setUp() runs before every test and takes 19.9s in total (password hashing 19.8s, db 166ms, factories 7ms) 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.16 s
- confs/tests.py:1175 TestEditConference.setUp · 2.82 s
- confs/tests.py:1177 TestEditConference.setUp · 2.64 s
- confs/tests.py:1176 TestEditConference.setUp · 2.58 s
- confs/tests.py:1371 TestApproveConference.setUp · 2.11 s
- confs/tests.py:1372 TestApproveConference.setUp · 2.06 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.24 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 1.23 s
- confs/tests.py:1296 TestUnapproveConference.setUp · 500 ms
- confs/tests.py:1295 TestUnapproveConference.setUp · 497 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
- confs/tests.py::TestApproveConference::test_non_staff_forbidden
Repeated queries (N+1) in the code under test
10 tests run the same query 10+ times, e.g. 45x in test_is_idempotent_and_refreshes_unposted_content. 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_is_idempotent_and_refreshes_unposted_content: 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_fwd50_date_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_two_facets_are_noindex: 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::TestSyncAnnouncements::test_is_idempotent_and_refreshes_unposted_content
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestMigratedLegacyConferences::test_fwd50_date_redirects
- accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
- 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
Make the test database server skip durability work
Tests spend 32.1s (47%) 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:
- fedidevs/db/postgresql/base.py:39 DatabaseWrapper.get_new_connection · 957 ms
- confs/tests.py:432 TestLegacyConferenceDataMigration._migrate · 938 ms
- starter_packs/tests.py:397 TestToggleStarterPackAccount.test_toggle_after_limit · 556 ms
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 449 ms
- starter_packs/views.py:862 share_starter_pack · 174 ms
- starter_packs/views.py:858 share_starter_pack · 170 ms
- confs/views.py:268 _conference_detail · 164 ms
- starter_packs/views.py:89 pack_header_avatars · 154 ms
- starter_packs/views.py:856 share_starter_pack · 135 ms
- stats/models.py:20 store_daily_stats · 134 ms
Most affected tests:
- confs/tests.py::TestSyncAnnouncements::test_is_idempotent_and_refreshes_unposted_content
- accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestMigratedLegacyConferences::test_fwd50_date_redirects
- 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::MastodonRatelimitHeaderTests::test_creates_session_with_hook_when_none_given
Disable django-debug-toolbar in tests
django-debug-toolbar is installed in the test settings and costs 6.1s.
Details
Where:
- accounts/views.py:425 index · 681 ms
- starter_packs/views.py:862 share_starter_pack · 324 ms
- confs/views.py:296 _conference_detail · 256 ms
- starter_packs/views.py:858 share_starter_pack · 170 ms
- confs/views.py:268 _conference_detail · 166 ms
- confs/views.py:509 create_conference · 155 ms
- starter_packs/views.py:89 pack_header_avatars · 154 ms
- starter_packs/views.py:856 share_starter_pack · 135 ms
- accounts/templatetags/account_extras.py:27 render_language_emojis · 125 ms
- accounts/views.py:28 CountlessPage.__init__ · 119 ms
Most affected tests:
- accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
- confs/tests.py::TestCreateConference::test_form_renders_for_authenticated_user
- confs/tests.py::TestMigratedLegacyConferences::test_fwd50_page
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- starter_packs/tests.py::TestShareStarterPack::test_order_by_6___not_a_valid_option____4__3__2__1__0__
- confs/tests.py::TestMigratedLegacyConferences::test_migrated_conference_shows_linked_posts
- confs/tests.py::TestCreateConference::test_advanced_days_are_saved
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
pytest-xdist workers finish at very different times
The busiest worker ran 23.7s of tests, the least busy 14.6s.
Details
pytest takes a long time before the first test runs
Startup takes 6.2s and collection 2.0s on every run, even when you only run one test.
Details
- mastodon_auth/tests.py (870ms)
- starter_packs/tests.py (269ms)
- accounts/tests.py (27ms)
- confs/tests.py (21ms)
- stats/tests.py (3ms)
- fedidevs/settings.py (1.4s)
- debug_toolbar/panels/sql/__init__.py (988ms)
- starter_packs/admin.py (652ms)
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.
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}
Tests
1–200 of 315, slowest first · click a column to sort this pageMemory
Busiest worker peaked at 217 MB; all 4 together at about 662 MB| Worker | Tests | Peak | Grew by |
|---|---|---|---|
| gw0 | 35 | 188 MB | 38 MB |
| gw1 | 132 | 204 MB | 53 MB |
| gw2 | 53 | 217 MB | 38 MB |
| gw3 | 95 | 213 MB | 62 MB |
Slowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 81 | 19.54 s |
| django_db_setup | session | 4 | 19.52 s |
| _unittest_setUpClass_fixture_TestShareStarterPack | class | 2 | 126 ms |
| _unittest_setUpClass_fixture_TestFollowBg | class | 2 | 111 ms |
| _unittest_setUpClass_fixture_TestSelectedInstance | class | 1 | 100 ms |
| _unittest_setUpClass_fixture_TestOwnerManagement | class | 2 | 90 ms |
| _unittest_setUpClass_fixture_TestPinAccountInStarterPack | class | 2 | 81 ms |
| _unittest_setUpClass_fixture_TestWebfingerBackfill | class | 1 | 74 ms |
| _unittest_setUpClass_fixture_TestRemoteFollowStarterPack | class | 3 | 67 ms |
| _unittest_setUpClass_fixture_TestEditStarterPackAccounts | class | 2 | 48 ms |
| _unittest_setUpClass_fixture_TestCreateStarterPack | class | 2 | 46 ms |
| _unittest_setUpClass_fixture_TestAddAccountsSearch | class | 1 | 39 ms |
| _unittest_setUpClass_fixture_TestToggleStarterPackAccount | class | 1 | 37 ms |
| _unittest_setUpClass_fixture_TestDeleteStarterPack | class | 1 | 33 ms |
| _unittest_setUpClass_fixture_TestEditStarterPack | class | 1 | 31 ms |