test: Fix flaky tests (#30107)

This commit is contained in:
Chillar Anand 2022-03-08 23:07:23 +05:30 committed by GitHub
parent edf043261e
commit ce27cdb121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 14 deletions

View File

@ -1,10 +1,9 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt # See license.txt
import unittest
import frappe import frappe
from frappe.utils import add_days, get_first_day, getdate, nowdate from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, get_first_day, getdate, now_datetime, nowdate
from erpnext.hr.doctype.attendance.attendance import ( from erpnext.hr.doctype.attendance.attendance import (
get_month_map, get_month_map,
@ -16,7 +15,7 @@ from erpnext.hr.doctype.leave_application.test_leave_application import get_firs
test_records = frappe.get_test_records('Attendance') test_records = frappe.get_test_records('Attendance')
class TestAttendance(unittest.TestCase): class TestAttendance(FrappeTestCase):
def test_mark_absent(self): def test_mark_absent(self):
employee = make_employee("test_mark_absent@example.com") employee = make_employee("test_mark_absent@example.com")
date = nowdate() date = nowdate()
@ -74,12 +73,14 @@ class TestAttendance(unittest.TestCase):
self.assertNotIn(first_sunday, unmarked_days) self.assertNotIn(first_sunday, unmarked_days)
def test_unmarked_days_as_per_joining_and_relieving_dates(self): def test_unmarked_days_as_per_joining_and_relieving_dates(self):
first_day = get_first_day(getdate()) now = now_datetime()
previous_month = now.month - 1
first_day = now.replace(day=1).replace(month=previous_month).date()
doj = add_days(first_day, 1) doj = add_days(first_day, 1)
relieving_date = add_days(first_day, 5) relieving_date = add_days(first_day, 5)
employee = make_employee('test_unmarked_days_as_per_doj@example.com', date_of_joining=doj, employee = make_employee('test_unmarked_days_as_per_doj@example.com', date_of_joining=doj,
date_of_relieving=relieving_date) relieving_date=relieving_date)
frappe.db.delete('Attendance', {'employee': employee}) frappe.db.delete('Attendance', {'employee': employee})
attendance_date = add_days(first_day, 2) attendance_date = add_days(first_day, 2)

View File

@ -1,6 +1,5 @@
import unittest
import frappe import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, getdate from frappe.utils import add_days, getdate
from erpnext.hr.doctype.employee.test_employee import make_employee from erpnext.hr.doctype.employee.test_employee import make_employee
@ -12,7 +11,7 @@ from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_
from erpnext.projects.report.project_profitability.project_profitability import execute from erpnext.projects.report.project_profitability.project_profitability import execute
class TestProjectProfitability(unittest.TestCase): class TestProjectProfitability(FrappeTestCase):
def setUp(self): def setUp(self):
frappe.db.sql('delete from `tabTimesheet`') frappe.db.sql('delete from `tabTimesheet`')
emp = make_employee('test_employee_9@salary.com', company='_Test Company') emp = make_employee('test_employee_9@salary.com', company='_Test Company')
@ -67,6 +66,3 @@ class TestProjectProfitability(unittest.TestCase):
fractional_cost = self.salary_slip.base_gross_pay * utilization fractional_cost = self.salary_slip.base_gross_pay * utilization
self.assertEqual(fractional_cost, row.fractional_cost) self.assertEqual(fractional_cost, row.fractional_cost)
def tearDown(self):
frappe.db.rollback()