From cd499d4955267cb0f50ee3e2928dda98845a1f8d Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 29 Jan 2026 15:43:47 +0530 Subject: [PATCH] refactor(test): make timesheet deterministic --- .../doctype/timesheet/test_timesheet.py | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 27536e59eda..01da979b31d 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -14,15 +14,6 @@ from erpnext.tests.utils import ERPNextTestSuite class TestTimesheet(ERPNextTestSuite): - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.make_projects() - cls.make_activity_type() - - def setUp(self): - frappe.db.delete("Timesheet") - def test_timesheet_post_update(self): frappe.get_doc( { @@ -73,7 +64,7 @@ class TestTimesheet(ERPNextTestSuite): ) def test_timesheet_base_amount(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) timesheet = make_timesheet(emp, simulate=True, is_billable=1) self.assertEqual(timesheet.time_logs[0].base_billing_rate, 50) @@ -82,7 +73,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(timesheet.time_logs[0].base_costing_amount, 40) def test_timesheet_billing_amount(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) timesheet = make_timesheet(emp, simulate=True, is_billable=1) self.assertEqual(timesheet.total_hours, 2) @@ -92,7 +83,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(timesheet.total_billable_amount, 100) def test_timesheet_billing_amount_not_billable(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) timesheet = make_timesheet(emp, simulate=True, is_billable=0) self.assertEqual(timesheet.total_hours, 2) @@ -120,7 +111,7 @@ class TestTimesheet(ERPNextTestSuite): @ERPNextTestSuite.change_settings("Projects Settings", {"fetch_timesheet_in_sales_invoice": 1}) def test_timesheet_billing_based_on_project(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) project = frappe.get_value("Project", {"project_name": "_Test Project"}) timesheet = make_timesheet( @@ -136,7 +127,7 @@ class TestTimesheet(ERPNextTestSuite): self.assertEqual(ts.time_logs[0].sales_invoice, sales_invoice.name) def test_timesheet_time_overlap(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) settings = frappe.get_single("Projects Settings") initial_setting = settings.ignore_employee_time_overlap @@ -192,7 +183,7 @@ class TestTimesheet(ERPNextTestSuite): settings.save() def test_timesheet_not_overlapping_with_continuous_timelogs(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) update_activity_type("_Test Activity Type") timesheet = frappe.new_doc("Timesheet") @@ -221,7 +212,7 @@ class TestTimesheet(ERPNextTestSuite): timesheet.save() # should not throw an error def test_to_time(self): - emp = make_employee("test_employee_6@salary.com") + emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name) from_time = now_datetime() timesheet = frappe.new_doc("Timesheet")