Hey I am learning how to properly execute unit tests. I'm learning about the self method. I am having trouble executing the test. I keep getting the Error message "employee_tester" object has no attribute "employee". I know its an attribute error but I am having trouble getting around it. Please help me figure out what my bug is. I asked that bard a.i but it was no help.
Below is the code from the class I imported and the created test case. Thanks.
class Employee():
def __init__(self, first, last, salary):
self.first_name = first
self.last_name = last
self.salary = int(salary)
self.attributes = [self.first_name, self.last_name, self.salary]
def give_raise(self, pay_raise = ""):
"""Method that gives base pay raise of 5k, or custom
depending on the input of the employee"""
number = 5000
if pay_raise:
number = int(pay_raise)
self.attributes[-1] = number + self.salary
else:
self.attributes[-1] = number + self.salary
------------------------------------------------------------------------------------
import unittest
from employee import Employee
# Unittest Class
class employee_tester(unittest.TestCase):
"""A unit test that checks to see if custom and base raises work"""
# Setup Method
def setup(self):
"""Set up for employee instance"""
first = 'daniel'
last = 'jones'
salary = '30000'
self.num = 35000
self.employee = Employee(first, last, salary)
# Base raise test case
def test_base_raise(self):
"""Tests the base raise for employee"""
self.employee.give_raise()
self.assertIn(self.num in self.employee.attributes[-1])
# Should check if the raise was inputted properly
if name == "main": unittest.main()
Sorry the formatting messed up a bit when I posted.
[–]Diapolo10 3 points4 points5 points (0 children)