From e2b554e1510acc5fd99efe4f4315649cb3c11e62 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 20 Apr 2026 10:37:31 +0530 Subject: [PATCH 1/3] chore(test): remove dead test code --- .../accounts/doctype/account/test_account.py | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/erpnext/accounts/doctype/account/test_account.py b/erpnext/accounts/doctype/account/test_account.py index 3629102ea5a..cdc278567a5 100644 --- a/erpnext/accounts/doctype/account/test_account.py +++ b/erpnext/accounts/doctype/account/test_account.py @@ -320,72 +320,6 @@ class TestAccount(ERPNextTestSuite): self.assertEqual(balance, 0) -def _make_test_records(verbose=None): - from frappe.tests.utils import make_test_objects - - accounts = [ - # [account_name, parent_account, is_group] - ["_Test Bank", "Bank Accounts", 0, "Bank", None], - ["_Test Bank USD", "Bank Accounts", 0, "Bank", "USD"], - ["_Test Bank EUR", "Bank Accounts", 0, "Bank", "EUR"], - ["_Test Cash", "Cash In Hand", 0, "Cash", None], - ["_Test Account Stock Expenses", "Direct Expenses", 1, None, None], - ["_Test Account Shipping Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], - ["_Test Account Customs Duty", "_Test Account Stock Expenses", 0, "Tax", None], - ["_Test Account Insurance Charges", "_Test Account Stock Expenses", 0, "Chargeable", None], - ["_Test Account Stock Adjustment", "_Test Account Stock Expenses", 0, "Stock Adjustment", None], - ["_Test Employee Advance", "Current Liabilities", 0, None, None], - ["_Test Account Tax Assets", "Current Assets", 1, None, None], - ["_Test Account VAT", "_Test Account Tax Assets", 0, "Tax", None], - ["_Test Account Service Tax", "_Test Account Tax Assets", 0, "Tax", None], - ["_Test Account Reserves and Surplus", "Current Liabilities", 0, None, None], - ["_Test Account Cost for Goods Sold", "Expenses", 0, None, None], - ["_Test Account Excise Duty", "_Test Account Tax Assets", 0, "Tax", None], - ["_Test Account Education Cess", "_Test Account Tax Assets", 0, "Tax", None], - ["_Test Account S&H Education Cess", "_Test Account Tax Assets", 0, "Tax", None], - ["_Test Account CST", "Direct Expenses", 0, "Tax", None], - ["_Test Account Discount", "Direct Expenses", 0, None, None], - ["_Test Write Off", "Indirect Expenses", 0, None, None], - ["_Test Exchange Gain/Loss", "Indirect Expenses", 0, None, None], - ["_Test Account Sales", "Direct Income", 0, None, None], - # related to Account Inventory Integration - ["_Test Account Stock In Hand", "Current Assets", 0, None, None], - # fixed asset depreciation - ["_Test Fixed Asset", "Current Assets", 0, "Fixed Asset", None], - ["_Test Accumulated Depreciations", "Current Assets", 0, "Accumulated Depreciation", None], - ["_Test Depreciations", "Expenses", 0, "Depreciation", None], - ["_Test Gain/Loss on Asset Disposal", "Expenses", 0, None, None], - # Receivable / Payable Account - ["_Test Receivable", "Current Assets", 0, "Receivable", None], - ["_Test Payable", "Current Liabilities", 0, "Payable", None], - ["_Test Receivable USD", "Current Assets", 0, "Receivable", "USD"], - ["_Test Payable USD", "Current Liabilities", 0, "Payable", "USD"], - ] - - for company, abbr in [ - ["_Test Company", "_TC"], - ["_Test Company 1", "_TC1"], - ["_Test Company with perpetual inventory", "TCP1"], - ]: - test_objects = make_test_objects( - "Account", - [ - { - "doctype": "Account", - "account_name": account_name, - "parent_account": parent_account + " - " + abbr, - "company": company, - "is_group": is_group, - "account_type": account_type, - "account_currency": currency, - } - for account_name, parent_account, is_group, account_type, currency in accounts - ], - ) - - return test_objects - - def get_inventory_account(company, warehouse=None): account = None if warehouse: From 7f021fb705629d70f397914f7b4866962949bfe2 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 20 Apr 2026 11:06:50 +0530 Subject: [PATCH 2/3] refactor(test): move create_test_contact_and_address to bootstrap --- .../selling/doctype/customer/test_customer.py | 4 +- .../delivery_trip/test_delivery_trip.py | 3 +- erpnext/tests/utils.py | 73 ++++++++----------- 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 211343966f9..5eef7f95651 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -14,7 +14,7 @@ from erpnext.selling.doctype.customer.customer import ( get_customer_outstanding, parse_full_name, ) -from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address +from erpnext.tests.utils import ERPNextTestSuite class TestCustomer(ERPNextTestSuite): @@ -71,8 +71,6 @@ class TestCustomer(ERPNextTestSuite): "customer_name": "_Test Customer", } - create_test_contact_and_address() - frappe.db.set_value( "Contact", "_Test Contact for _Test Customer-_Test Customer", "is_primary_contact", 1 ) diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py index 783a28a47d8..83b7395f342 100644 --- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py +++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py @@ -10,7 +10,7 @@ from erpnext.stock.doctype.delivery_trip.delivery_trip import ( get_contact_and_address, notify_customers, ) -from erpnext.tests.utils import ERPNextTestSuite, create_test_contact_and_address +from erpnext.tests.utils import ERPNextTestSuite class TestDeliveryTrip(ERPNextTestSuite): @@ -19,7 +19,6 @@ class TestDeliveryTrip(ERPNextTestSuite): driver = create_driver() create_vehicle() create_delivery_notification() - create_test_contact_and_address() address = create_address(driver) self.delivery_trip = create_delivery_trip(driver, address, company="_Test Company") diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index e2a2a7ab195..0544f0e3383 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -16,49 +16,6 @@ ReportFilters = dict[str, Any] ReportName = NewType("ReportName", str) -def create_test_contact_and_address(): - frappe.db.sql("delete from tabContact") - frappe.db.sql("delete from `tabContact Email`") - frappe.db.sql("delete from `tabContact Phone`") - frappe.db.sql("delete from tabAddress") - frappe.db.sql("delete from `tabDynamic Link`") - - frappe.get_doc( - { - "doctype": "Address", - "address_title": "_Test Address for Customer", - "address_type": "Office", - "address_line1": "Station Road", - "city": "_Test City", - "state": "Test State", - "country": "India", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], - } - ).insert() - - contact = frappe.get_doc( - { - "doctype": "Contact", - "first_name": "_Test Contact for _Test Customer", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], - } - ) - contact.add_email("test_contact_customer@example.com", is_primary=True) - contact.add_phone("+91 0000000000", is_primary_phone=True) - contact.insert() - - contact_two = frappe.get_doc( - { - "doctype": "Contact", - "first_name": "_Test Contact 2 for _Test Customer", - "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], - } - ) - contact_two.add_email("test_contact_two_customer@example.com", is_primary=True) - contact_two.add_phone("+92 0000000000", is_primary_phone=True) - contact_two.insert() - - def execute_script_report( report_name: ReportName, module: str, @@ -241,6 +198,7 @@ class BootStrapTestData: self.make_sales_person() self.make_activity_type() self.make_address() + self.make_contact() self.update_support_settings() self.update_selling_settings() self.update_stock_settings() @@ -2859,9 +2817,38 @@ class BootStrapTestData: {"link_doctype": "Customer", "link_name": "_Test Customer 1", "doctype": "Dynamic Link"} ], }, + { + "doctype": "Address", + "address_title": "_Test Address for Customer", + "address_type": "Office", + "address_line1": "Station Road", + "city": "_Test City", + "state": "Test State", + "country": "India", + "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], + }, ] self.make_records(["address_title", "address_type"], records) + def make_contact(self): + records = [ + { + "doctype": "Contact", + "first_name": "_Test Contact for _Test Customer", + "email_ids": [{"email_id": "test_contact_customer@example.com", "is_primary": True}], + "phone_nos": [{"phone": "+91 0000000000", "is_primary_phone": True}], + "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], + }, + { + "doctype": "Contact", + "first_name": "_Test Contact 2 for _Test Customer", + "email_ids": [{"email_id": "test_contact_two_customer@example.com", "is_primary": True}], + "phone_nos": [{"phone": "+92 0000000000", "is_primary_phone": True}], + "links": [{"link_doctype": "Customer", "link_name": "_Test Customer"}], + }, + ] + self.make_records(["first_name"], records) + def make_dimensions(self): records = [ { From 336be9d8203d97ef512588c8aa1b36228213bdad Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 20 Apr 2026 13:53:03 +0530 Subject: [PATCH 3/3] refactor(test): set instance variables before calling utility method --- .../accounts_receivable/test_accounts_receivable.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index b4004e3a3b8..8f879aa50f4 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -772,7 +772,7 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin): def test_party_account_filter(self): si1 = self.create_sales_invoice() - self.customer2 = frappe.get_doc( + jane = frappe.get_doc( { "doctype": "Customer", "customer_name": "Jane Doe", @@ -781,9 +781,9 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin): } ).insert() + self.customer = jane.name si2 = self.create_sales_invoice(do_not_submit=True) si2.posting_date = add_days(today(), -1) - si2.customer = self.customer2.name si2.currency = "USD" si2.conversion_rate = 80 si2.debit_to = self.debtors_usd @@ -991,7 +991,7 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin): self.assertEqual(expected_data, report_output) def test_future_payments_on_foreign_currency(self): - self.customer2 = frappe.get_doc( + jane = frappe.get_doc( { "doctype": "Customer", "customer_name": "Jane Doe", @@ -999,10 +999,10 @@ class TestAccountsReceivable(ERPNextTestSuite, AccountsTestMixin): "default_currency": "USD", } ).insert() + self.customer = jane.name si = self.create_sales_invoice(do_not_submit=True) si.posting_date = add_days(today(), -1) - si.customer = self.customer2.name si.currency = "USD" si.conversion_rate = 80 si.debit_to = self.debtors_usd