TypeError: is_peak() missing 1 required positional argument: ‘start_time’

  git, pycharm, python, testing, unit-testing

I can’t seem to figure out why my unittest is not running. enter image description here

I am trying to test the methods in calculator class:

class Calculator():

def __init__(self):
    pass

def is_peak(self, start_time: str):
    time = start_time.split(':')  # Extracts the hour character from the string
    hour = time[0]
    int_hour = int(hour)
    if 6 <= int_hour < 18:
        return True
    else:
        return False

This is the testcase for unittest:

class TestCalculator(unittest.TestCase):

def test_peak(self):
    # testCase 1 (User enters a valid time in the peak hour)
    self.assertEqual(True, Calculator.is_peak('9:40'))

    # # testCase 2 (User enters a valid time in the off-peak hour)
    self.assertEqual(True, Calculator.is_peak('20:30'))

Source: Python Questions

LEAVE A COMMENT