test: run shared setup once per class to speed up lending tests#1297
Draft
Nihantra-Patel wants to merge 7 commits into
Draft
test: run shared setup once per class to speed up lending tests#1297Nihantra-Patel wants to merge 7 commits into
Nihantra-Patel wants to merge 7 commits into
Conversation
Move the master data setup (loan accounts, products, securities and customers) from setUp to setUpClass in the lending test suites. Before, this setup ran again before every single test in a class, even though the data is the same for all of them. Now it runs only once per test class. Each test still gets a fresh applicant lookup in setUp where needed, and the per-test rollback from the base test case keeps the tests isolated. This cuts the run time of the smaller test classes by about 40-50% (for example TestLoanInterestAccrual went from about 23s to 13s). The heavier tests are unchanged because their time is real work, not setup.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1297 +/- ##
===========================================
+ Coverage 82.54% 82.59% +0.05%
===========================================
Files 154 154
Lines 10846 10929 +83
===========================================
+ Hits 8953 9027 +74
- Misses 1893 1902 +9
🚀 New features to boost your workflow:
|
Some loan repayment tests ran interest accrual and daily demand processing for more months than the test actually paid against or checked. The extra months only added run time without changing what the test verifies. Reduce the processing span to the last month that is used in each test: - test_in_between_payments and test_in_between_cancellations: 4 -> 3 - test_bulk_payments, test_bulk_repayment_logs and test_bulk_payments_for_multiple_disbursements: 6 -> 5 All assertions and paid amounts are unchanged. The tests still pass and run noticeably faster (for example test_bulk_payments dropped from about 60s to about 25s locally).
The CI MariaDB container holds a disposable test database, so its durability guarantees are not needed. Relax them to avoid disk I/O that dominates the test run time: - innodb-flush-log-at-trx-commit=0: no fsync on every commit (biggest win) - sync-binlog=0: skip binary-log syncs - innodb-doublewrite=0: skip the doublewrite buffer - mount the data dir on tmpfs (RAM) so the test DB does no disk I/O These mirror the tuning already used by frappe and erpnext CI. They are safe only because the database is recreated for every run.
test_bulk_repayment_logs and test_bulk_payments_for_multiple_disbursements assert on Bulk Repayment Log status, not on Loan Repayment behaviour, so they belong with the Bulk Repayment Log doctype rather than in the already large loan repayment test file. Move both into bulk_repayment_log/test_bulk_repayment_log.py (with the same shared class setup). No test logic changes; both still pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Moves the shared test setup (loan accounts, loan products, securities and customers) from
setUpintosetUpClassacross the lending test suites.Why
setUpruns before every single test. The lending tests were rebuilding the same master data again and again for each test in a class, even though the data never changed between tests. This was a big part of why each test took several seconds.setUpClassruns only once per test class, so the heavy setup happens one time instead of once per test.What stays the same
setUpwhere it is needed.Result