refactor(test): make bom tests deterministic

This commit is contained in:
ruthra kumar
2025-11-29 12:33:23 +05:30
parent 7b26a4c2eb
commit bfb8837c54
2 changed files with 49 additions and 0 deletions

View File

@@ -394,6 +394,7 @@ class TestBOM(ERPNextTestSuite):
item_code = make_item(properties={"is_stock_item": 1}).name
bom = frappe.new_doc("BOM")
bom.company = self.companies[0].name
bom.item = item_code
bom.append("items", frappe._dict(item_code=item_code))
bom.save()
@@ -407,11 +408,13 @@ class TestBOM(ERPNextTestSuite):
item2 = make_item(properties={"is_stock_item": 1}).name
bom1 = frappe.new_doc("BOM")
bom1.company = self.companies[0].name
bom1.item = item1
bom1.append("items", frappe._dict(item_code=item2))
bom1.save()
bom2 = frappe.new_doc("BOM")
bom2.company = self.companies[0].name
bom2.item = item2
bom2.append("items", frappe._dict(item_code=item1))
bom2.save()
@@ -569,6 +572,7 @@ class TestBOM(ERPNextTestSuite):
@timeout
def test_clear_inpection_quality(self):
bom = frappe.copy_doc(self.globalTestRecords["BOM"][2], ignore_no_copy=True)
bom.company = self.companies[0].name
bom.docstatus = 0
bom.is_default = 0
bom.quality_inspection_template = "_Test Quality Inspection Template"
@@ -614,6 +618,7 @@ class TestBOM(ERPNextTestSuite):
# Step 1: Create BOM
bom = frappe.new_doc("BOM")
bom.company = self.companies[0].name
bom.item = fg_item.item_code
bom.quantity = 1
bom.append(

View File

@@ -242,6 +242,8 @@ class ERPNextTestSuite(unittest.TestCase):
cls.make_workstation()
cls.make_operation()
cls.make_bom()
cls.make_quality_inspection_param()
cls.make_quality_inspection_template()
cls.update_selling_settings()
cls.update_stock_settings()
cls.update_system_settings()
@@ -2839,6 +2841,48 @@ class ERPNextTestSuite(unittest.TestCase):
else:
cls.bom.append(frappe.get_doc("BOM", {"item": x.get("item"), "company": x.get("company")}))
@classmethod
def make_quality_inspection_param(cls):
records = [{"doctype": "Quality Inspection Parameter", "parameter": "_Test Param"}]
cls.quality_inspection_param = []
for x in records:
if not frappe.db.exists("Quality Inspection Parameter", {"parameter": x.get("parameter")}):
cls.quality_inspection_param.append(frappe.get_doc(x).insert())
else:
cls.quality_inspection_param.append(
frappe.get_doc("Quality Inspection Parameter", {"parameter": x.get("parameter")})
)
@classmethod
def make_quality_inspection_template(cls):
records = [
{
"quality_inspection_template_name": "_Test Quality Inspection Template",
"doctype": "Quality Inspection Template",
"item_quality_inspection_parameter": [
{
"specification": cls.quality_inspection_param[0].name,
"doctype": "Item Quality Inspection Parameter",
"parentfield": "item_quality_inspection_parameter",
}
],
}
]
cls.quality_inspection_template = []
for x in records:
if not frappe.db.exists(
"Quality Inspection Template",
{"quality_inspection_template_name": x.get("quality_inspection_template_name")},
):
cls.quality_inspection_template.append(frappe.get_doc(x).insert())
else:
cls.quality_inspection_template.append(
frappe.get_doc(
"Quality Inspection Template",
{"quality_inspection_template_name": x.get("quality_inspection_template_name")},
)
)
@contextmanager
def set_user(self, user: str):
try: