1

I am looking for some assistance in determining why a test I wrote doesn't work. Initially I wrote the test program like this and it worked and still does:

import unittest
from employee_info import EmployeeData
class TestEmployee(unittest.TestCase):
def setUp(self):
 self.david_scott = EmployeeData('david', 'scott', 60000)
def test_give_custom_raise(self):
 self.david_scott.give_raise(5200)
 self.assertEqual(self.david_scott.annual_salary, 65200)

unittest.main()

Later the same day, I was practicing and re-wrote the same exact code as shown below, and it will not work!

import unittest
from employee_info import EmployeeData
class TestEmployee(unittest.TestCase):
def setUP(self):
 self.david_scott = EmployeeData('david', 'scott', 60000)
def test_give_custom_raise(self):
 self.david_scott.give_raise(5200)
 self.assertEqual(self.david_scott.annual_salary, 65200)
unittest.main()

To trouble shoot, I copied the original code that did work and pasted it into the same open file and it worked as expected. At this point, I have spent 2 hours now trying to figure out why pasting the first code into the file works fine, while pasting the second one returns the following error:

======================================================================

ERROR: test_give_custom_raise (main.TestEmployee)

Traceback (most recent call last): File "/Users/DavinChace/Desktop/python_work/Chapter 15 - Generating Data/employee_test_module.py", line 10, in test_give_custom_raise self.david_scott.give_raise(5200) AttributeError: 'TestEmployee' object has no attribute 'david_scott'


Ran 1 test in 0.000s

FAILED (errors=1)

I have tried copying both codes into microsoft word and excel to compare them line for line and they are exactly the same. Any ideas as to what could be causing one code to work while the other fails? To be clear, in both instances the code was ran in the same open file.

Hamza Anis
2,5651 gold badge28 silver badges38 bronze badges
asked Aug 19, 2018 at 2:57

1 Answer 1

2

You appear to have misnamed the setUp() function:

def setUP(self):
 self.david_scott = EmployeeData('david', 'scott', 60000)

setUp is not the same as setUP.

answered Aug 19, 2018 at 3:01
Sign up to request clarification or add additional context in comments.

1 Comment

WOW thank you! I swear I spent so many hours and could not see the small but very important difference.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.