Passed Run of Nov 7, 23:52
pytest --flakytest-profile --flakytest-rate 2000.
Where the time goes
Test time by category- Password hashing16.28 s
- Migrations14.16 s
- Libraries9.31 s
- Database8.49 s
- DB schema2.79 s
- Imports1.01 s
- Templates979 ms
- Mocking855 ms
- pytest264 ms
- Unsampled250 ms
- Factories188 ms
- App code65 ms
- Deep copies41 ms
- Cache13 ms
- Waiting12 ms
- Test code12 ms
- Network11 ms
- Logging10 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
16.3s (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 · 2.91 s
- confs/tests.py:1176 TestEditConference.setUp · 2.25 s
- confs/tests.py:1177 TestEditConference.setUp · 2.23 s
- confs/tests.py:1175 TestEditConference.setUp · 2.18 s
- confs/tests.py:1371 TestApproveConference.setUp · 1.65 s
- confs/tests.py:1372 TestApproveConference.setUp · 1.63 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 1.03 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.03 s
- confs/tests.py:1296 TestUnapproveConference.setUp · 403 ms
- confs/tests.py:1295 TestUnapproveConference.setUp · 401 ms
Most affected tests:
- 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::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestApproveConference::test_staff_approves
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestApproveConference::test_non_staff_forbidden
Use plain static file storage in tests
Static file storage/manifest handling costs 13.7s.
Details
Where:
- starter_packs/views.py:862 share_starter_pack · 413 ms
- accounts/views.py:425 index · 397 ms
- starter_packs/tests.py:736 TestShareStarterPack.test_non_discoverable_accounts · 324 ms
- confs/tests.py:875 TestConferencePage.test_conference_with_utc_with_date_no_posts · 276 ms
- starter_packs/tests.py:125 TestCreateStarterPack.test_form_error · 264 ms
- accounts/tests.py:536 TestStaticPages.test_developers_on_mastodon · 254 ms
- starter_packs/tests.py:1068 TestPinAccountInStarterPack.test_pin_limit · 251 ms
- confs/tests.py:1153 TestCreateConference.test_rejects_more_than_three_icons · 249 ms
- starter_packs/tests.py:841 TestShareStarterPack.test_api_formats · 225 ms
- confs/tests.py:193 TestMigratedLegacyConferences.test_djangoconus_date_redirects · 221 ms
Most affected tests:
- starter_packs/tests.py::TestShareStarterPack::test_non_discoverable_accounts
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- starter_packs/tests.py::TestCreateStarterPack::test_form_error
- accounts/tests.py::TestStaticPages::test_developers_on_mastodon
- starter_packs/tests.py::TestPinAccountInStarterPack::test_pin_limit
- confs/tests.py::TestCreateConference::test_rejects_more_than_three_icons
- starter_packs/tests.py::TestEditStarterPackAccounts::test_not_owned_starter_pack
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_date_redirects
Stop re-running migrations on every test run
Migrations take 14.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 · 640 ms
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 355 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:388 _get_or_create_conference · 103 ms
- confs/tests.py:412 TestLegacyConferenceDataMigration._leaf_targets · 78 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:214 _pk_batches · 48 ms
- confs/tests.py:430 TestLegacyConferenceDataMigration._migrate · 43 ms
- confs/tests.py:431 TestLegacyConferenceDataMigration._migrate · 33 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:398 migrate_legacy_pair · 29 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:325 _refresh_account_counts · 27 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:368 _attach_lookups_and_tags · 21 ms
Most affected tests:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- 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
- 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 15.9s in total (password hashing 15.7s, db 159ms, factories 6ms) in 7 classes: TestApproveConference (6 tests), TestFollowStarterPack (3 tests), TestPostAnnouncements (6 tests), TestCreateConference (10 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 · 2.92 s
- confs/tests.py:1176 TestEditConference.setUp · 2.26 s
- confs/tests.py:1177 TestEditConference.setUp · 2.25 s
- confs/tests.py:1175 TestEditConference.setUp · 2.19 s
- confs/tests.py:1371 TestApproveConference.setUp · 1.66 s
- confs/tests.py:1372 TestApproveConference.setUp · 1.64 s
- confs/tests.py:1316 TestConferenceApprovalVisibility.setUp · 1.03 s
- confs/tests.py:1317 TestConferenceApprovalVisibility.setUp · 1.03 s
- confs/tests.py:1296 TestUnapproveConference.setUp · 405 ms
- confs/tests.py:1295 TestUnapproveConference.setUp · 404 ms
Most affected tests:
- 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::TestEditConference::test_owner_can_edit
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestApproveConference::test_staff_approves
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- 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_fwd50_date_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_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_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_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
- 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
- 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_fwd50_date_redirects
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
- confs/tests.py::TestSyncAnnouncements::test_is_idempotent_and_refreshes_unposted_content
- 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 5.6s.
Details
Where:
- starter_packs/views.py:862 share_starter_pack · 413 ms
- accounts/views.py:425 index · 397 ms
- accounts/tests.py:536 TestStaticPages.test_developers_on_mastodon · 240 ms
- accounts/views.py:28 CountlessPage.__init__ · 218 ms
- starter_packs/views.py:185 starter_packs · 209 ms
- starter_packs/views.py:60 get_editable_pack · 164 ms
- accounts/views.py:295 index · 142 ms
- accounts/templatetags/account_extras.py:36 instances_datalist · 121 ms
- confs/views.py:509 create_conference · 114 ms
- starter_packs/splash_images.py:77 get_splash_image_accounts · 113 ms
Most affected tests:
- accounts/tests.py::TestStaticPages::test_developers_on_mastodon
- accounts/tests.py::TestAccountIndexRobots::test_two_facets_are_noindex
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestCreateConference::test_form_renders_for_authenticated_user
- confs/tests.py::TestCreateConference::test_advanced_days_are_saved
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- fedidevs/tests.py::TestAnonymousCacheAndCsrf::test_anonymous_forms_work_after_csrf_bootstrap
- starter_packs/tests.py::TestStarterPacks::test_index_page
Make the test database server skip durability work
Tests spend 25.4s (46%) 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 · 640 ms
- starter_packs/tests.py:397 TestToggleStarterPackAccount.test_toggle_after_limit · 448 ms
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 355 ms
- starter_packs/views.py:862 share_starter_pack · 274 ms
- accounts/views.py:28 CountlessPage.__init__ · 218 ms
- starter_packs/views.py:60 get_editable_pack · 164 ms
- stats/models.py:20 store_daily_stats · 144 ms
- accounts/views.py:295 index · 142 ms
- stats/models.py:12 store_daily_stats · 136 ms
- accounts/templatetags/account_extras.py:36 instances_datalist · 121 ms
Most affected tests:
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- 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
- 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
pytest-xdist workers finish at very different times
The busiest worker ran 19.0s of tests, the least busy 11.6s.
Details
pytest takes a long time before the first test runs
Startup takes 5.0s and collection 1.5s on every run, even when you only run one test.
Details
- mastodon_auth/tests.py (603ms)
- starter_packs/tests.py (221ms)
- accounts/tests.py (52ms)
- confs/tests.py (10ms)
- posts/tests.py (2ms)
- fedidevs/settings.py (970ms)
- debug_toolbar/panels/sql/__init__.py (793ms)
- starter_packs/admin.py (677ms)
Run migrations once, not once per worker
Each of the 4 pytest-xdist workers builds its own test database by running every migration: 15.1s in total, about 3.8s per worker. 11.3s 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': 15.062, 'builds': 4, 'workers': 4, 'per_build': 3.765}
Tests
201–310 of 310, slowest first · click a column to sort this pageMemory
Busiest worker peaked at 210 MB; all 4 together at about 652 MB| Worker | Tests | Peak | Grew by |
|---|---|---|---|
| gw0 | 76 | 210 MB | 43 MB |
| gw1 | 103 | 187 MB | 43 MB |
| gw2 | 96 | 205 MB | 60 MB |
| gw3 | 35 | 183 MB | 42 MB |
Slowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 78 | 15.08 s |
| django_db_setup | session | 4 | 15.06 s |
| _unittest_setUpClass_fixture_TestShareStarterPack | class | 3 | 146 ms |
| _unittest_setUpClass_fixture_TestSelectedInstance | class | 1 | 91 ms |
| _unittest_setUpClass_fixture_TestFollowStarterPack | class | 2 | 82 ms |
| _unittest_setUpClass_fixture_TestPinAccountInStarterPack | class | 2 | 69 ms |
| _unittest_setUpClass_fixture_TestOwnerManagement | class | 2 | 65 ms |
| _unittest_setUpClass_fixture_TestWebfingerBackfill | class | 1 | 60 ms |
| _unittest_setUpClass_fixture_TestEditStarterPackAccounts | class | 2 | 49 ms |
| _unittest_setUpClass_fixture_TestFollowBg | class | 1 | 44 ms |
| _unittest_setUpClass_fixture_TestCreateStarterPack | class | 2 | 43 ms |
| _unittest_setUpClass_fixture_TestAddAccountsSearch | class | 1 | 40 ms |
| _unittest_setUpClass_fixture_TestStarterPacks | class | 1 | 34 ms |
| _unittest_setUpClass_fixture_TestConferencePage | class | 1 | 31 ms |
| _unittest_setUpClass_fixture_TestRemoteFollowStarterPack | class | 2 | 29 ms |