From fe9d6e5a570ca1afe36ebc65edfea6d8cb4059bc Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 12 Sep 2026 14:23:11 +0530 Subject: [PATCH] test: remove seven tests that cannot fail (#59024) Four tests in test_stock_entry.py each cover only an early-return guard: def test_validate_job_card_item_skips_when_no_job_card(self): se = frappe.new_doc("Stock Entry") se.job_card = None se.validate_job_card_item() # must not raise That exercises `if not self.job_card: return` and nothing else. The mismatch tests next to them already cover the behaviour these validators actually implement. Three tests in test_payment_request.py assert against their own mock. _is_v2_gateway delegates to payments.utils.is_v2_gateway; all three mock that delegate to return False and then assert the result is False, for inputs (None, "", "NonExistentGateway12345") that take an identical code path. The mock decides the outcome, so the assertion holds regardless of what ERPNext does. The three tests covering the real branches -- delegation, a False delegate, and the exception fallback -- are kept. --- .../payment_request/test_payment_request.py | 34 ------------------- .../doctype/stock_entry/test_stock_entry.py | 21 ------------ 2 files changed, 55 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py index d76cfe6c138..a77187ef417 100644 --- a/erpnext/accounts/doctype/payment_request/test_payment_request.py +++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py @@ -1041,40 +1041,6 @@ class TestPaymentRequestV2Gateway(ERPNextTestSuite): mock_payments.utils = mock_utils return {"payments": mock_payments, "payments.utils": mock_utils}, mock_utils - def test_is_v2_gateway_returns_false_for_none(self): - """_is_v2_gateway returns False for None input.""" - from erpnext.accounts.doctype.payment_request.payment_request import _is_v2_gateway - - # Mock returns True, but is_v2_gateway(None) in payments.utils returns False - modules, mock_utils = self._mock_payments_modules(False) - - with patch.dict(sys.modules, modules): - result = _is_v2_gateway(None) - self.assertFalse(result) - mock_utils.is_v2_gateway.assert_called_once_with(None) - - def test_is_v2_gateway_returns_false_for_empty_string(self): - """_is_v2_gateway returns False for empty string input.""" - from erpnext.accounts.doctype.payment_request.payment_request import _is_v2_gateway - - modules, mock_utils = self._mock_payments_modules(False) - - with patch.dict(sys.modules, modules): - result = _is_v2_gateway("") - self.assertFalse(result) - mock_utils.is_v2_gateway.assert_called_once_with("") - - def test_is_v2_gateway_returns_false_for_nonexistent_gateway(self): - """_is_v2_gateway returns False for nonexistent gateway.""" - from erpnext.accounts.doctype.payment_request.payment_request import _is_v2_gateway - - modules, mock_utils = self._mock_payments_modules(False) - - with patch.dict(sys.modules, modules): - result = _is_v2_gateway("NonExistentGateway12345") - self.assertFalse(result) - mock_utils.is_v2_gateway.assert_called_once_with("NonExistentGateway12345") - def test_is_v2_gateway_delegates_to_payments_util(self): """_is_v2_gateway delegates to payments.utils.is_v2_gateway.""" from erpnext.accounts.doctype.payment_request.payment_request import _is_v2_gateway diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 6edd798901b..c158a2d5b3b 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -4444,11 +4444,6 @@ class TestStockEntryCoverage(ERPNextTestSuite): # ── validate_source_stock_entry ──────────────────────────────────────────── - def test_validate_source_stock_entry_skips_when_no_source(self): - se = frappe.new_doc("Stock Entry") - se.source_stock_entry = None - se.validate_source_stock_entry() # must not raise - def test_validate_source_stock_entry_throws_on_work_order_mismatch(self): source_se = make_stock_entry( item_code="_Test Item", @@ -4480,11 +4475,6 @@ class TestStockEntryCoverage(ERPNextTestSuite): # ── validate_job_card_fg_item ────────────────────────────────────────────── - def test_validate_job_card_fg_item_skips_when_no_job_card(self): - se = frappe.new_doc("Stock Entry") - se.job_card = None - se.validate_job_card_fg_item() # must not raise - def test_validate_job_card_fg_item_throws_when_fg_item_mismatches(self): wrong_fg = make_item("_JC Wrong FG Item", {"is_stock_item": 1}).name @@ -4503,17 +4493,6 @@ class TestStockEntryCoverage(ERPNextTestSuite): # ── validate_job_card_item ───────────────────────────────────────────────── - def test_validate_job_card_item_skips_when_no_job_card(self): - se = frappe.new_doc("Stock Entry") - se.job_card = None - se.validate_job_card_item() # must not raise - - def test_validate_job_card_item_skips_for_manufacture_purpose(self): - se = frappe.new_doc("Stock Entry") - se.job_card = "SOME-JC-001" - se.purpose = "Manufacture" - se.validate_job_card_item() # must not raise even with a job card set - @ERPNextTestSuite.change_settings("Manufacturing Settings", {"job_card_excess_transfer": 0}) def test_validate_job_card_item_throws_when_job_card_item_ref_missing(self): jc_name = frappe.db.get_value("Job Card", {"docstatus": 1})