最近在学习Python中遇到了一点问题。
下面是employee.py文件中的代码:
class Employee():
def init(self,first_name,last_name,pay):
self.first_name = first_name.title()
self.last_name = last_name.title()
self.pay = pay
def give_raise(self,pay_raise=5000):
self.pay += pay_raise
再下面是主代码:
import unittest
from employee import Employee
class TestEmployee(unittest.TestCase):
def SetUp(self):
self.employee = Employee('taylor','swift',20000)
def test_give_default_raise(self):
self.employee.give_raise()
self.assertEqual(self.self.pay,25000)
unittest.main()
运行之后发生的错误:
AttributeError: 'TestEmployee' object has no attribute 'employee'
请问是怎么回事呢?又该怎么解决呢?谢谢大家。
def SetUp(self):
self.employee = Employee('taylor','swift',20000)
改为 SetUp ==> setUp
def setUp(self):
self.employee = Employee('taylor','swift',20000)
谢谢。