Passed Run of Oct 18, 22:55
Where the time goes
Test time by category- Database11.66 s
- Libraries5.74 s
- Migrations2.74 s
- Password hashing1.93 s
- DB schema1.60 s
- Templates537 ms
- Serialization373 ms
- App code310 ms
- Imports296 ms
- pytest156 ms
- Unsampled145 ms
- Deep copies100 ms
- Factories28 ms
- Waiting21 ms
- Test code13 ms
- Logging3 ms
- Cache2 ms
- Mocking2 ms
Session timeline
Fix next
Ranked by the time each fix saves per runRun tests in parallel on all 2 CPUs
Tests run one at a time: 25.6s of test time on a 2-CPU machine. With pytest-xdist this could take about 12.8s.
Details
Tests must not share state: files in fixed paths, ports, a shared database without per-worker names, or module globals. Run with -p randomly first to shake out order dependencies.
Use plain static file storage in tests
Static file storage/manifest handling costs 11.0s.
Details
Where:
- apps/api/tests.py:487 ProfileUploadTest.upload · 563 ms
- apps/mcp/tests.py:66 McpTest.post · 558 ms
- ft/tests.py:203 TestAccountSettings.test_change_password · 415 ms
- apps/orgs/tests.py:28 SignupTest.test_signing_up_creates_an_organization · 289 ms
- ft/tests.py:159 TestAccountPages.test_signup · 235 ms
- apps/projects/urls.py:498 project_profile · 211 ms
- ft/tests.py:198 TestAccountSettings.test_change_password · 203 ms
- apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 203 ms
- ft/tests.py:96 TestTrubleshootingPage.test_troubleshooting · 195 ms
- apps/api/tests.py:58 TestInvalidIngest.test_ingest_invalid · 191 ms
Most affected tests:
- ft/tests.py::TestAccountSettings::test_change_password
- apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
- apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
- ft/tests.py::TestAccountPages::test_signup
- apps/api/tests.py::ProfileUploadTest::test_missing_parts_mark_the_profile_incomplete
- ft/tests.py::TestTrubleshootingPage::test_troubleshooting
- apps/api/tests.py::TestInvalidIngest::test_ingest_invalid
- apps/projects/tests.py::IndexPageTest::test_index_page
Disable django-debug-toolbar in tests
django-debug-toolbar is installed in the test settings and costs 6.5s.
Details
Where:
- ft/tests.py:203 TestAccountSettings.test_change_password · 415 ms
- apps/orgs/tests.py:28 SignupTest.test_signing_up_creates_an_organization · 278 ms
- ft/tests.py:159 TestAccountPages.test_signup · 235 ms
- apps/projects/urls.py:498 project_profile · 211 ms
- ft/tests.py:198 TestAccountSettings.test_change_password · 203 ms
- apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 203 ms
- apps/projects/tests.py:88 IndexPageTest.test_index_page · 144 ms
- apps/orgs/views.py:33 org_shell · 118 ms
- apps/projects/analytics.py:264 latest_profiles · 118 ms
- apps/projects/urls.py:40 can_manage_project · 111 ms
Most affected tests:
- ft/tests.py::TestAccountSettings::test_change_password
- apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
- apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
- ft/tests.py::TestAccountPages::test_signup
- apps/api/tests.py::ProfileUploadTest::test_missing_parts_mark_the_profile_incomplete
- apps/projects/tests.py::IndexPageTest::test_index_page
- apps/projects/tests.py::ProjectPagesTest::test_dashboard_public_by_slug
- apps/projects/tests.py::ProfilePagePaginationTest::test_slowest_tests_first_then_the_next_page
Repeated queries (N+1) in the code under test
27 tests run the same query 10+ times, e.g. 180x in test_seed_demo. 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.
- 180x in test_seed_demo: SELECT "projects_test"."id", "projects_test"."name", "projects_test"."project_id", "projects_test"."slug", "projects_test"."date_last_run", "projects_test"."date_first_seen", "projects_test"."first_commit_id", "projects_test"."muted" FROM "projects_test" WHERE ("projects_test"."name" = %s AND "proj…
- 22x in test_dashboard_filters: SELECT "projects_environment"."id", "projects_environment"."project_id", "projects_environment"."name", "projects_environment"."kind", "projects_environment"."provider", "projects_environment"."details", "projects_environment"."date_first_seen", "projects_environment"."date_last_seen" FROM "project…
- 21x in test_configure_page: SELECT "projects_profile"."id", "projects_profile"."project_id", "projects_profile"."number", "projects_profile"."environment_id", "projects_profile"."session_id", "projects_profile"."run_id", "projects_profile"."commit_id", "projects_profile"."ingest_id", "projects_profile"."external_id", "project…
- 20x in test_index: SELECT "django_content_type"."model" AS "model" FROM "django_content_type" WHERE "django_content_type"."app_label" = %s
- 20x in test_daily_stats_count_a_profile_once_every_part_is_in: SELECT "projects_profilepart"."id", "projects_profilepart"."profile_id", "projects_profilepart"."index", "projects_profilepart"."count", "projects_profilepart"."checksum", "projects_profilepart"."status", "projects_profilepart"."error", "projects_profilepart"."tests_count", "projects_profilepart"."…
Most affected tests:
- apps/projects/tests.py::SeedDemoCommandTest::test_seed_demo
- apps/projects/tests.py::ProjectPagesTest::test_dashboard_filters
- apps/projects/tests.py::ProjectPagesTest::test_configure_page
- apps/api/tests.py::TestApiIndex::test_index
- apps/api/tests.py::ProfileUploadTest::test_daily_stats_count_a_profile_once_every_part_is_in
- apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
- apps/api/tests.py::IngestStartEndpointTest::test_details_are_kept_for_failures_only
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
Make the test database server skip durability work
Tests spend 16.0s (62%) 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:
- apps/api/tests.py:76 IngestStartEndpointTest.join_workers · 462 ms
- apps/projects/models.py:466 Profile.save · 324 ms
- apps/projects/profiles.py:313 write_snapshots · 239 ms
- apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 203 ms
- apps/projects/environments.py:63 get_or_create_environment · 196 ms
- apps/projects/profiles.py:458 write_perfs · 171 ms
- apps/projects/tests.py:953 ProjectPagesTest.setUp · 168 ms
- apps/api/tests.py:73 IngestStartEndpointTest.setUp · 165 ms
- apps/projects/rollups.py:88 add_perfs · 162 ms
- apps/projects/models.py:230 TestManager.upsert · 146 ms
Most affected tests:
- apps/api/tests.py::TestApiIndex::test_index
- apps/projects/tests.py::SeedDemoCommandTest::test_seed_demo
- apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_progress_end
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_progress_before_start
- apps/api/tests.py::IngestStartEndpointTest::test_results_are_counted_and_the_payload_dropped
- apps/projects/tests.py::ProjectPagesTest::test_configure_page
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
Stop re-running migrations on every test run
Migrations take 2.7s 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:
- apps/projects/migrations/0014_backfill_session_counts.py:23 backfill · 3 ms
- apps/projects/migrations/0016_profile_parts.py:9 move_documents · 3 ms
- apps/projects/migrations/0022_backfill_organizations.py:48 forwards · 3 ms
- apps/projects/migrations/0009_auto_20240218_1217.py:12 create_mute_objects · 2 ms
- apps/projects/migrations/0014_backfill_session_counts.py:18 backfill.<locals>.count · 2 ms
- apps/projects/migrations/0015_store_compressed_documents_as_is.py:12 external_storage · 2 ms
- apps/projects/migrations/0022_backfill_organizations.py:69 forwards · 2 ms
Most affected tests:
- apps/api/tests.py::TestApiIndex::test_index
pytest takes a long time before the first test runs
Startup takes 5.3s and collection 278ms on every run, even when you only run one test.
Use a fast password hasher in tests
1.9s (8% 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:
- ft/tests.py:203 TestAccountSettings.test_change_password · 408 ms
- apps/orgs/tests.py:28 SignupTest.test_signing_up_creates_an_organization · 230 ms
- ft/tests.py:230 TestAccountSettings.test_projects_only_lists_your_own_even_for_superusers · 230 ms
- apps/orgs/tests.py:194 SuperuserTest.test_superusers_can_open_any_project_but_dont_list_them · 230 ms
- ft/tests.py:159 TestAccountPages.test_signup · 223 ms
- ft/tests.py:213 TestAccountSettings.test_change_password · 212 ms
- ft/tests.py:198 TestAccountSettings.test_change_password · 202 ms
- ft/tests.py:175 TestAccountSettings.setUpTestData · 194 ms
Most affected tests:
- ft/tests.py::TestAccountSettings::test_change_password
- apps/orgs/tests.py::SignupTest::test_signing_up_creates_an_organization
- ft/tests.py::TestAccountSettings::test_projects_only_lists_your_own_even_for_superusers
- apps/orgs/tests.py::SuperuserTest::test_superusers_can_open_any_project_but_dont_list_them
- ft/tests.py::TestAccountPages::test_signup
Use TestCase instead of TransactionTestCase
1.4s goes to flushing every table after tests in 11 TransactionTestCase / transaction=True / live_server tests.
Details
Tests that rely on commit behaviour, multiple connections or a live server still need a transactional test case.
Most affected tests:
- apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_progress_end
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_with_git
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
- apps/api/tests.py::ProfileUploadLockTest::test_upload_while_a_part_is_being_processed
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_progress_before_start
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_valid
- apps/api/tests.py::ProfileUploadQueueTest::test_upload_is_processed_by_the_worker
Tests open new database connections over and over
Connecting to the database takes 962ms.
Details
Where:
- apps/api/tests.py:76 IngestStartEndpointTest.join_workers · 177 ms
- apps/api/tests.py:73 IngestStartEndpointTest.setUp · 105 ms
- apps/api/tasks.py:266 warm_reports · 68 ms
- apps/api/urls.py:72 api_request.<locals>.decorator.<locals>.wrapped_view · 52 ms
- apps/api/tests.py:928 ProfileUploadLockTest.setUp · 14 ms
- apps/api/tests.py:235 IngestStartEndpointTest.test_ingest_progress_before_start · 13 ms
- apps/api/tests.py:257 IngestStartEndpointTest.test_ingest_end_after_progress · 12 ms
- apps/api/tasks.py:237 process_profile · 11 ms
- apps/api/tests.py:988 ProfileUploadQueueTest.test_upload_is_processed_by_the_worker · 11 ms
- apps/api/tests.py:212 IngestStartEndpointTest.test_ingest_start_progress_end · 11 ms
Most affected tests:
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_progress_before_start
- apps/api/tests.py::IngestStartEndpointTest::test_results_are_counted_and_the_payload_dropped
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_progress_end
- apps/api/tests.py::IngestStartEndpointTest::test_all_test_status_types
- apps/api/tests.py::ProfileUploadQueueTest::test_upload_is_processed_by_the_worker
- apps/api/tests.py::IngestStartEndpointTest::test_details_are_kept_for_failures_only
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_with_git
Create shared test data in setUpTestData instead of setUp
setUp() runs before every test and takes 862ms in total (db 788ms, library 69ms, factories 3ms) in 13 classes: SettingsTest (3 tests), ProjectsPageTest (5 tests), ProjectEditPage (6 tests), ProjectDeletePage (4 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:
- apps/projects/tests.py:953 ProjectPagesTest.setUp · 192 ms
- apps/api/tests.py:73 IngestStartEndpointTest.setUp · 167 ms
- apps/projects/tests.py:142 ProjectEditPage.setUp · 61 ms
- apps/projects/tests.py:268 ProjectRunsPage.setUp · 55 ms
- ft/tests.py:179 TestAccountSettings.setUp · 47 ms
- apps/projects/tests.py:412 TestProjectTestPage.setUp · 46 ms
- apps/projects/tests.py:1375 MemoryTest.setUp · 46 ms
- apps/projects/tests.py:100 ProjectsPageTest.setUp · 45 ms
- apps/projects/tests.py:218 ProjectCreatePage.setUp · 44 ms
- apps/projects/tests.py:187 ProjectDeletePage.setUp · 36 ms
Most affected tests:
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_start_with_git
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_valid
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_multiple_sessions
- apps/api/tests.py::IngestStartEndpointTest::test_results_are_counted_and_the_payload_dropped
- apps/api/tests.py::IngestStartEndpointTest::test_ingest_end_after_progress
- apps/api/tests.py::ProfileUploadLockTest::test_upload_while_a_part_is_being_processed
- apps/projects/tests.py::ProjectRunsPage::test_project_with_runs
- apps/api/tests.py::IngestStartEndpointTest::test_details_are_kept_for_failures_only
Tests
1–200 of 235, slowest first · click a column to sort this pageMemory
The test process peaked at 198 MBSlowest fixtures
Exact setup time across the session| Fixture | Scope | Calls | Total |
|---|---|---|---|
| _django_setup_unittest | class | 50 | 3.03 s |
| django_db_setup | session | 1 | 3.01 s |
| _unittest_setUpClass_fixture_ProjectPagesTest | class | 1 | 279 ms |
| _unittest_setUpClass_fixture_RealProfileDocumentTest | class | 1 | 263 ms |
| _unittest_setUpClass_fixture_ProfilePagePaginationTest | class | 1 | 220 ms |
| _unittest_setUpClass_fixture_TestAccountSettings | class | 1 | 206 ms |
| _unittest_setUpClass_fixture_AnalyticsTest | class | 1 | 202 ms |
| _unittest_setUpClass_fixture_McpTest | class | 1 | 186 ms |
| _unittest_setUpClass_fixture_MemoryTest | class | 1 | 90 ms |
| _unittest_setUpClass_fixture_StorageTest | class | 1 | 81 ms |
| _unittest_setUpClass_fixture_FlakyReportTest | class | 1 | 68 ms |
| _unittest_setUpClass_fixture_LegacyUrlTest | class | 1 | 60 ms |
| _unittest_setUpClass_fixture_FlakyReportCacheTest | class | 1 | 47 ms |
| _unittest_setUpClass_fixture_ProjectTestsPage | class | 1 | 19 ms |
| _unittest_setUpClass_fixture_ProjectRunPage | class | 1 | 19 ms |