From cdcd60a1ea40d997b783f40c275a152dcf202840 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 23 Feb 2022 16:09:37 +0530 Subject: [PATCH] chore: Rollback after each test, due to premature commit via `remove_user_permission` (backport #29964) (#29967) * chore: Rollback after each test, due to premature commit via `remove_user_permission` - `remove_user_permission` in `test_warehouse_user` calls delete_doc that enqueues dynamic link deletion - Execution of background job eventually commits - While in the test suite it runs sequentially in the same thread and commits whatever was done until then - Which is why the rollback in `tearDownClass` is quite useless here - This premature commit causes many illegal transactions caught by `assertRaises` to be committed in the db - This creates faulty/dirty ledgers and breaks reports, as outiside the test suite this shouldn't/wouldn't happen - Rollback after each test, and for `test_warehouse_user` in particular, manually cancel transaction (cherry picked from commit bf8743713dcb318958c01e693c6d1071fd5fc218) # Conflicts: # erpnext/stock/doctype/stock_entry/test_stock_entry.py * test: Make Variant if absent in `test_variant_work_order`, keep test atomic (cherry picked from commit 5ff3705872960190031066dbe34158ad3c659820) * fix: Merge conflicts Co-authored-by: marination --- erpnext/stock/doctype/stock_entry/test_stock_entry.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 3d936c50f7a..3c34d4795cb 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -45,6 +45,7 @@ def get_sle(**args): class TestStockEntry(ERPNextTestCase): def tearDown(self): + frappe.db.rollback() frappe.set_user("Administrator") frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0") @@ -566,6 +567,7 @@ class TestStockEntry(ERPNextTestCase): st1.set_stock_entry_type() st1.insert() st1.submit() + st1.cancel() frappe.set_user("Administrator") remove_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com") @@ -690,6 +692,8 @@ class TestStockEntry(ERPNextTestCase): bom_no = frappe.db.get_value("BOM", {"item": "_Test Variant Item", "is_default": 1, "docstatus": 1}) + make_item_variant() # make variant of _Test Variant Item if absent + work_order = frappe.new_doc("Work Order") work_order.update({ "company": "_Test Company", @@ -1101,13 +1105,10 @@ class TestStockEntry(ERPNextTestCase): # Check if FG cost is calculated based on RM total cost # RM total cost = 200, FG rate = 200/4(FG qty) = 50 - self.assertEqual(se.items[1].basic_rate, 50) + self.assertEqual(se.items[1].basic_rate, flt(se.items[0].basic_rate/4)) self.assertEqual(se.value_difference, 0.0) self.assertEqual(se.total_incoming_value, se.total_outgoing_value) - # teardown - se.delete() - def make_serialized_item(**args): args = frappe._dict(args) se = frappe.copy_doc(test_records[0])