From 3398e051903e2a742ad18fe3f0f2ee7e0d03da9f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Jun 2026 13:27:39 +0530 Subject: [PATCH] test: reuse BootStrapTestData master data to reduce runtime Co-Authored-By: Claude Opus 4.8 (1M context) --- .../test_product_bundle_balance.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/report/product_bundle_balance/test_product_bundle_balance.py b/erpnext/stock/report/product_bundle_balance/test_product_bundle_balance.py index 865403b8528..4403db6fcd7 100644 --- a/erpnext/stock/report/product_bundle_balance/test_product_bundle_balance.py +++ b/erpnext/stock/report/product_bundle_balance/test_product_bundle_balance.py @@ -8,7 +8,7 @@ from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.report.product_bundle_balance.product_bundle_balance import execute from erpnext.tests.utils import ERPNextTestSuite -WH = "_Test Warehouse - _TC" +WH = "Stores - _TC" class TestProductBundleBalance(ERPNextTestSuite): @@ -24,20 +24,28 @@ class TestProductBundleBalance(ERPNextTestSuite): return execute(filters)[1] def test_bundle_qty_is_limited_by_scarcest_child(self): + # Reuse the bootstrap stock items as children. They start at zero in `Stores - _TC`, + # so transacting there gives a clean, deterministic balance for this warehouse's row. parent = make_item(properties={"is_stock_item": 0, "is_sales_item": 1}).name - child_a = make_item(properties={"is_stock_item": 1}).name - child_b = make_item(properties={"is_stock_item": 1}).name + child_a = "_Test Item" + child_b = "_Test Item 2" self.make_bundle(parent, {child_a: 2, child_b: 1}) make_stock_entry(item_code=child_a, to_warehouse=WH, qty=10, rate=100) make_stock_entry(item_code=child_b, to_warehouse=WH, qty=3, rate=100) data = self.run_report(parent) - parent_row = next(r for r in data if r["item_code"] == parent and r["indent"] == 0) + parent_row = next( + r for r in data if r["item_code"] == parent and r["indent"] == 0 and r["warehouse"] == WH + ) # min(10 // 2, 3 // 1) = min(5, 3) = 3 buildable bundles self.assertEqual(parent_row["bundle_qty"], 3) - row_a = next(r for r in data if r["item_code"] == child_a and r["indent"] == 1) - row_b = next(r for r in data if r["item_code"] == child_b and r["indent"] == 1) + row_a = next( + r for r in data if r["item_code"] == child_a and r["indent"] == 1 and r["warehouse"] == WH + ) + row_b = next( + r for r in data if r["item_code"] == child_b and r["indent"] == 1 and r["warehouse"] == WH + ) self.assertEqual((row_a["actual_qty"], row_a["minimum_qty"], row_a["bundle_qty"]), (10, 2, 5)) self.assertEqual((row_b["actual_qty"], row_b["minimum_qty"], row_b["bundle_qty"]), (3, 1, 3))