Python Test Not Working

Python Test Not Working



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:



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



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.




1 Answer
1



You appear to have misnamed the setUp() function:


setUp()


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



setUp is not the same as setUP.


setUp


setUP





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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

Henj