Skip to content

perf(tests): significantly improve test execution time#1298

Merged
CAPITAINMARVEL merged 1 commit intoBeanieODM:mainfrom
staticxterm:speedup-tests
Mar 13, 2026
Merged

perf(tests): significantly improve test execution time#1298
CAPITAINMARVEL merged 1 commit intoBeanieODM:mainfrom
staticxterm:speedup-tests

Conversation

@staticxterm
Copy link
Member

@staticxterm staticxterm commented Mar 12, 2026

This PR refactors the test infrastructure to significantly improve the test execution speed.

🚀 Performance

Test runtime improved substantially:

Locally (on my machine)

  • Before: ~7 minutes (430s)
  • After: ~1.5 minute (95s)
  • ~4.5x faster

Key changes

  • Switched core fixtures (settings, cli, db) to session scope to reuse MongoDB connections.
  • Run init_beanie() once per test session instead of per test.
  • Added an automatic database cleanup fixture to ensure test isolation and to reset the model cache because of the new "shared" approach.
  • Added time-machine test dependency for deterministic cache-expiration testing instead of introducing real delays.
  • Minor test cleanups and lint configuration adjustments.

Result

  • Faster test execution
  • Reduced database/client initialization overhead
  • Deterministic cache behavior in tests
  • More consistent and maintainable test setup

@staticxterm staticxterm requested review from a team, CAPITAINMARVEL and Riverfount March 12, 2026 00:52
Copy link
Contributor

@CAPITAINMARVEL CAPITAINMARVEL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good nice speed up

@CAPITAINMARVEL CAPITAINMARVEL enabled auto-merge (squash) March 12, 2026 14:51
@staticxterm staticxterm requested review from a team and roman-right March 12, 2026 16:32
Copy link

@Riverfount Riverfount left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CAPITAINMARVEL CAPITAINMARVEL merged commit bf2bc7c into BeanieODM:main Mar 13, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants