Passed Run of Oct 18, 16:00
pytest --flakytest-profile --flakytest-rate 2000.
Where the time goes
Test time by category- Password hashing48.68 s
- Libraries38.89 s
- Migrations37.10 s
- Database12.10 s
- DB schema3.64 s
- Mocking3.39 s
- Templates2.54 s
- Imports2.35 s
- pytest974 ms
- Factories595 ms
- Unsampled297 ms
- App code105 ms
- Deep copies84 ms
- Waiting56 ms
- Network44 ms
- Cache41 ms
- Test code34 ms
- Logging13 ms
- Serialization5 ms
Session timeline
Fix next
Ranked by the time each fix saves per runUse plain static file storage in tests
Static file storage/manifest handling costs 47.8s.
Details
Where:
- starter_packs/tests.py:841 test_api_formats · 1.40 s
- confs/tests.py:1407 test_staff_sees_approve_button_on_detail · 1.24 s
- starter_packs/tests.py:781 test_order_by · 1.13 s
- accounts/tests.py:550 assert_noindex · 1.09 s
- accounts/views.py:428 index · 1.01 s
- confs/tests.py:152 _assert_no_naive_warning · 780 ms
- accounts/tests.py:536 test_developers_on_mastodon · 687 ms
- accounts/tests.py:555 assert_indexable · 668 ms
- starter_packs/tests.py:1087 test_unpinned_pack_orders_by_followers · 639 ms
- starter_packs/tests.py:198 test_not_owned_starter_pack · 602 ms
Most affected tests:
- confs/tests.py::TestApproveConference::test_staff_sees_approve_button_on_detail
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- accounts/tests.py::TestStaticPages::test_developers_on_mastodon
- starter_packs/tests.py::TestPinAccountInStarterPack::test_unpinned_pack_orders_by_followers
- starter_packs/tests.py::TestEditStarterPack::test_not_owned_starter_pack
- confs/tests.py::TestConferencePage::test_conference_with_pacific_with_date
- starter_packs/tests.py::TestStarterPacks::test_index_page_language_filter
- confs/tests.py::TestCreateConference::test_mastodon_url_is_kept
Use a fast password hasher in tests
48.7s (32% 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:1176 setUp · 8.75 s
- confs/tests.py:1044 setUp · 8.65 s
- confs/tests.py:1175 setUp · 6.80 s
- confs/tests.py:1177 setUp · 6.20 s
- confs/tests.py:1371 setUp · 4.92 s
- confs/tests.py:1372 setUp · 3.73 s
- confs/tests.py:1317 setUp · 3.30 s
- confs/tests.py:1316 setUp · 3.21 s
- fedidevs/tests.py:62 test_authenticated_html_is_private_and_keeps_csrf_header · 1.11 s
- confs/tests.py:1296 setUp · 716 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_owner_sees_edit_button_on_approved_detail
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestConferenceApprovalVisibility::test_pending_detail_page_is_viewable
- confs/tests.py::TestEditConference::test_requires_login
Stop re-running migrations on every test run
Migrations take 37.1s 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 _migrate · 2.68 s
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 688 ms
- confs/tests.py:412 _leaf_targets · 291 ms
- confs/tests.py:431 _migrate · 158 ms
- confs/tests.py:430 _migrate · 141 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:388 _get_or_create_conference · 124 ms
- confs/tests.py:485 _seed_overlapping_legacy_data · 119 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:214 _pk_batches · 92 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:398 migrate_legacy_pair · 65 ms
- confs/migrations/0033_remove_legacy_conference_tables.py:368 _attach_lookups_and_tags · 56 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
- 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 47.2s in total (password hashing 46.9s, db 311ms, factories 19ms) in 7 classes: TestPostAnnouncements (6 tests), TestFollowStarterPack (3 tests), TestCreateConference (10 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:1176 setUp · 8.77 s
- confs/tests.py:1044 setUp · 8.67 s
- confs/tests.py:1175 setUp · 6.82 s
- confs/tests.py:1177 setUp · 6.21 s
- confs/tests.py:1371 setUp · 4.94 s
- confs/tests.py:1372 setUp · 3.74 s
- confs/tests.py:1317 setUp · 3.31 s
- confs/tests.py:1316 setUp · 3.22 s
- confs/tests.py:1296 setUp · 717 ms
- confs/tests.py:1295 setUp · 636 ms
Most affected tests:
- confs/tests.py::TestEditConference::test_other_user_forbidden_on_approved_conference
- confs/tests.py::TestEditConference::test_owner_sees_edit_button_on_approved_detail
- confs/tests.py::TestEditConference::test_owner_can_edit_after_approval
- confs/tests.py::TestEditConference::test_owner_can_view_edit_form
- confs/tests.py::TestEditConference::test_other_user_forbidden
- confs/tests.py::TestEditConference::test_edit_does_not_change_slug
- confs/tests.py::TestConferenceApprovalVisibility::test_pending_detail_page_is_viewable
- 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_single_facet_is_indexable. 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_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
- 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
- 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::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
- confs/tests.py::TestMigratedLegacyConferences::test_djangoconus_old_url_redirects
- 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 52.8s (35%) 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 _migrate · 2.68 s
- starter_packs/tests.py:397 test_toggle_after_limit · 819 ms
- confs/migrations/0031_seed_conference_tags.py:14 seed_conference_tags · 688 ms
- stats/models.py:20 store_daily_stats · 311 ms
- confs/tests.py:412 _leaf_targets · 291 ms
- stats/models.py:12 store_daily_stats · 222 ms
- starter_packs/views.py:865 share_starter_pack · 191 ms
- confs/tests.py:431 _migrate · 158 ms
- confs/tests.py:430 _migrate · 141 ms
- starter_packs/views.py:60 get_editable_pack · 133 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::TestMigratedLegacyConferences::test_djangoconus_old_url_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::RegisterAppTests::test_returns_credentials_on_200
Disable django-debug-toolbar in tests
django-debug-toolbar is installed in the test settings and costs 9.9s.
Details
Where:
- accounts/views.py:428 index · 1.01 s
- confs/views.py:299 _conference_detail · 502 ms
- starter_packs/views.py:865 share_starter_pack · 492 ms
- confs/views.py:512 create_conference · 271 ms
- starter_packs/views.py:188 starter_packs · 203 ms
- confs/tests.py:1407 test_staff_sees_approve_button_on_detail · 198 ms
- starter_packs/tests.py:781 test_order_by · 164 ms
- accounts/templatetags/account_extras.py:27 render_language_emojis · 138 ms
- starter_packs/views.py:60 get_editable_pack · 133 ms
- starter_packs/views.py:729 share_starter_pack · 127 ms
Most affected tests:
- accounts/tests.py::TestAccountIndexRobots::test_single_facet_is_indexable
- accounts/tests.py::TestSelectedInstance::test_invalid_selected_instance
- confs/tests.py::TestApproveConference::test_staff_sees_approve_button_on_detail
- confs/tests.py::TestConferencePage::test_conference_with_utc_with_date_no_posts
- confs/tests.py::TestCreateConference::test_form_renders_for_authenticated_user
- accounts/tests.py::TestSelectedInstance::test_selected_instance_through_session
- confs/tests.py::TestMigratedLegacyConferences::test_migrated_conference_shows_linked_posts
- confs/tests.py::TestMigratedLegacyConferences::test_dotnetconf_page
Tests
201–301 of 301, slowest first · click a column to sort this pageMemory
Busiest worker peaked at 211 MB; all 4 together at about 679 MB| Worker | Tests | Peak | Grew by |
|---|---|---|---|
| gw0 | 133 | 201 MB | 57 MB |
| gw1 | 103 | 197 MB | 57 MB |
| gw2 | 32 | 211 MB | 37 MB |
| gw3 | 33 | 174 MB | 33 MB |
Slowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 69 | 36.78 s |
| django_db_setup | session | 4 | 36.71 s |
| _unittest_setUpClass_fixture_TestSelectedInstance | class | 1 | 279 ms |
| _unittest_setUpClass_fixture_TestShareStarterPack | class | 2 | 205 ms |
| _unittest_setUpClass_fixture_TestOwnerManagement | class | 2 | 138 ms |
| _unittest_setUpClass_fixture_TestConferencePage | class | 2 | 136 ms |
| _unittest_setUpClass_fixture_TestPinAccountInStarterPack | class | 2 | 134 ms |
| _unittest_setUpClass_fixture_TestFollowStarterPack | class | 2 | 130 ms |
| _unittest_setUpClass_fixture_TestEditStarterPackAccounts | class | 2 | 103 ms |
| _unittest_setUpClass_fixture_TestFollowBg | class | 1 | 100 ms |
| _unittest_setUpClass_fixture_TestWebfingerBackfill | class | 1 | 91 ms |
| _template_string_if_invalid_marker | function | 301 | 59 ms |
| _unittest_setUpClass_fixture_TestStarterPacks | class | 1 | 57 ms |
| _django_set_urlconf | function | 301 | 53 ms |
| _unittest_setUpClass_fixture_TestEditStarterPack | class | 1 | 46 ms |