From 0d333894c930b96878e374b3bb474a5e2d5329f9 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Thu, 25 Jul 2019 23:37:43 +0530 Subject: [PATCH] perf(tests): Use setUpClass and tearDownClass instead of setUp and tearDown --- .../doctype/purchase_invoice/test_purchase_invoice.py | 7 +++++-- .../accounts/doctype/sales_invoice/test_sales_invoice.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index b4d584fbde..6deee38148 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -20,11 +20,13 @@ test_dependencies = ["Item", "Cost Center", "Payment Term", "Payment Terms Templ test_ignore = ["Serial No"] class TestPurchaseInvoice(unittest.TestCase): - def setUp(self): + @classmethod + def setUpClass(self): unlink_payment_on_cancel_of_invoice() frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) - def tearDown(self): + @classmethod + def tearDownClass(self): unlink_payment_on_cancel_of_invoice(0) def test_gl_entries_without_perpetual_inventory(self): @@ -91,6 +93,7 @@ class TestPurchaseInvoice(unittest.TestCase): pi_doc = frappe.get_doc('Purchase Invoice', pi_doc.name) self.assertRaises(frappe.LinkExistsError, pi_doc.cancel) + unlink_payment_on_cancel_of_invoice() def test_purchase_invoice_for_blocked_supplier(self): supplier = frappe.get_doc('Supplier', '_Test Supplier') diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 52470fde95..dff55947df 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -29,10 +29,12 @@ class TestSalesInvoice(unittest.TestCase): w.submit() return w - def setUp(self): + @classmethod + def setUpClass(self): unlink_payment_on_cancel_of_invoice() - def tearDown(self): + @classmethod + def tearDownClass(self): unlink_payment_on_cancel_of_invoice(0) def test_timestamp_change(self): @@ -135,6 +137,7 @@ class TestSalesInvoice(unittest.TestCase): unlink_payment_on_cancel_of_invoice(0) si = frappe.get_doc('Sales Invoice', si.name) self.assertRaises(frappe.LinkExistsError, si.cancel) + unlink_payment_on_cancel_of_invoice() def test_sales_invoice_calculation_export_currency(self): si = frappe.copy_doc(test_records[2])