From 199d04eb80b3d7b268cf872fb4bc9ea01319ce75 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 26 Nov 2024 12:39:19 +0100 Subject: [PATCH] fix(test): Handle explicit commit in create_custom_field - `create_custom_field` cannot be used arbitrarily in tests since it explicitly commits to make sure schema changes are reflected - Call it during setUpClass since 2 tests need it - Call it first so that after the commit, the following test setup can be rolled back on class cleanup - Rollback to the post setup state after each test so that there is no test-run data shared between tests --- .github/helper/install.sh | 2 +- .../test_bank_reconciliation_tool_beta.py | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/helper/install.sh b/.github/helper/install.sh index c3668c06..7c8acac0 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -32,7 +32,7 @@ bench get-app erpnext --branch version-15 bench get-app hrms --branch version-15 bench get-app banking "${GITHUB_WORKSPACE}" -bench start &> bench_run_logs.txt & +bench start &> bench_start.log & bench new-site --db-root-password root --admin-password admin test_site --install-app erpnext bench --site test_site install-app hrms bench --site test_site install-app banking diff --git a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/test_bank_reconciliation_tool_beta.py b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/test_bank_reconciliation_tool_beta.py index d8f62549..8581312b 100644 --- a/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/test_bank_reconciliation_tool_beta.py +++ b/banking/klarna_kosma_integration/doctype/bank_reconciliation_tool_beta/test_bank_reconciliation_tool_beta.py @@ -32,20 +32,28 @@ class TestBankReconciliationToolBeta(AccountsTestMixin, FrappeTestCase): - def setUp(self) -> None: + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + + create_custom_field( + "Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data") + ) # commits to db internally + create_bank() - self.gl_account = create_gl_account("_Test Bank Reco Tool") - self.bank_account = create_bank_account(gl_account=self.gl_account) - self.customer = create_customer(customer_name="ABC Inc.") + cls.gl_account = create_gl_account("_Test Bank Reco Tool") + cls.bank_account = create_bank_account(gl_account=cls.gl_account) + cls.customer = create_customer(customer_name="ABC Inc.") - self.create_item( - item_name="Reco Item", company="_Test Company", warehouse="Finished Goods - _TC" + cls.create_item( + cls, item_name="Reco Item", company="_Test Company", warehouse="Finished Goods - _TC" ) + frappe.db.savepoint(save_point="bank_reco_beta_before_tests") def tearDown(self) -> None: """Runs after each test.""" # Make sure invoices are rolled back to not affect invoice count assertions - frappe.db.rollback() + frappe.db.rollback(save_point="bank_reco_beta_before_tests") def test_unpaid_invoices_more_than_transaction(self): """ @@ -562,10 +570,6 @@ def test_multi_party_reconciliation(self): def test_configurable_reference_field(self): """Test if configured reference field is considered.""" - create_custom_field( - "Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data") - ) - settings = frappe.get_single("Banking Settings") settings.append( "reference_fields", {"document_type": "Sales Invoice", "field_name": "custom_ref_no"} @@ -622,9 +626,6 @@ def test_configurable_reference_field(self): def test_no_configurable_reference_field(self): """Test if Name is considered as the reference field if not configured.""" - create_custom_field( - "Sales Invoice", dict(fieldname="custom_ref_no", label="Ref No", fieldtype="Data") - ) bt = create_bank_transaction( date=getdate(), deposit=300,