refactor(test): move commits inside test guard clause

This commit is contained in:
ruthra kumar
2026-03-20 11:46:43 +05:30
parent cd5b0ea5fd
commit ed76d6699a
11 changed files with 28 additions and 13 deletions

View File

@@ -489,4 +489,5 @@ def rename_temporarily_named_docs(doctype):
for hook in frappe.get_hooks(hook_type):
frappe.call(hook, newname=newname, oldname=oldname)
if not frappe.in_test:
frappe.db.commit()

View File

@@ -71,6 +71,7 @@ def start_merge(docname):
ledger_merge.account,
)
row.db_set("merged", 1)
if not frappe.in_test:
frappe.db.commit()
successful_merges += 1
frappe.publish_realtime(

View File

@@ -274,6 +274,7 @@ def start_import(invoices):
doc.flags.ignore_mandatory = True
doc.insert(set_name=invoice_number)
doc.submit()
if not frappe.in_test:
frappe.db.commit()
names.append(doc.name)
except Exception:

View File

@@ -750,6 +750,7 @@ def make_payment_request(**args):
pr.submit()
if args.order_type == "Shopping Cart":
if not frappe.in_test:
frappe.db.commit()
frappe.local.response["type"] = "redirect"
frappe.local.response["location"] = pr.get_payment_url()

View File

@@ -772,6 +772,7 @@ def process_all(subscription: list, posting_date: DateTimeLikeObject | None = No
try:
subscription = frappe.get_doc("Subscription", subscription_name)
subscription.process(posting_date)
if not frappe.in_test:
frappe.db.commit()
except frappe.ValidationError:
frappe.db.rollback()

View File

@@ -62,7 +62,9 @@ def book_depreciation_entries(date):
accounting_dimensions,
)
if not frappe.in_test:
frappe.db.commit()
except Exception as e:
frappe.db.rollback()
failed_assets.append(asset_name)
@@ -72,6 +74,7 @@ def book_depreciation_entries(date):
if failed_assets:
set_depr_entry_posting_status_for_failed_assets(failed_assets)
notify_depr_entry_posting_error(failed_assets, error_logs)
if not frappe.in_test:
frappe.db.commit()

View File

@@ -785,6 +785,7 @@ def make_purchase_invoice_from_portal(purchase_order_name: str):
if frappe.session.user not in frappe.get_all("Portal User", {"parent": doc.supplier}, pluck="user"):
frappe.throw(_("Not Permitted"), frappe.PermissionError)
doc.save()
if not frappe.in_test:
frappe.db.commit()
frappe.response["type"] = "redirect"
frappe.response.location = "/purchase-invoices/" + doc.name

View File

@@ -120,6 +120,7 @@ class Appointment(Document):
self.auto_assign()
self.create_calendar_event()
self.save(ignore_permissions=True)
if not frappe.in_test:
frappe.db.commit()
def create_lead_and_link(self):

View File

@@ -926,7 +926,7 @@ def update_transactions_annual_history(company, commit=False):
transactions_history = get_all_transactions_annual_history(company)
frappe.db.set_value("Company", company, "transactions_annual_history", json.dumps(transactions_history))
if commit:
if commit and not frappe.in_test:
frappe.db.commit()
@@ -935,6 +935,8 @@ def cache_companies_monthly_sales_history():
for company in companies:
update_company_monthly_sales(company)
update_transactions_annual_history(company)
if not frappe.in_test:
frappe.db.commit()

View File

@@ -31,6 +31,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False,
for d in item_warehouses:
try:
repost_stock(d[0], d[1], allow_zero_rate, only_actual, only_bin, allow_negative_stock)
if not frappe.in_test:
frappe.db.commit()
except Exception:
frappe.db.rollback()

View File

@@ -190,6 +190,8 @@ def link_existing_conversations(doc, state):
call_log = frappe.get_doc("Call Log", log)
call_log.add_link(link_type=doc.doctype, link_name=doc.name)
call_log.save(ignore_permissions=True)
if not frappe.in_test:
frappe.db.commit()
except Exception:
frappe.log_error(title=_("Error during caller information update"))