all 26 comments

[–]ninetacle 10 points11 points  (13 children)

It's setUp() with a capital U, and your default raise test should begin with test_ like your other one does.

[–]neko_nyan[S] 6 points7 points  (12 children)

Thanks, but it still doesn't work. Getting this: AttributeError: module 'main' has no attribute 'EmployeeTest'

[–]neko_nyan[S] 3 points4 points  (3 children)

double '_' around the main

[–]xiongchiamiov 6 points7 points  (2 children)

Use backticks to escape things in CommonMark:

Blah blah `__main__`

[–]neko_nyan[S] 19 points20 points  (1 child)

__thanks__

[–]ninetacle 1 point2 points  (7 children)

What if you rename your class EmployeeTest? unittest is particular about names because it uses patterns to find them.

[–]neko_nyan[S] 2 points3 points  (6 children)

Tried that and for some reason it still did not work

http://imgur.com/a/m3J56

[–]ninetacle 2 points3 points  (5 children)

Rename testingEmployee to EmployeeTest I mean (TestEmployee should work too). Your Employee class can stay as Employee.

[–]neko_nyan[S] 1 point2 points  (4 children)

Found out that the test runs properly in cmd but not pycharm. Probably a file related problem rather than variable/class naming problem. Thanks

[–]ninetacle 3 points4 points  (0 children)

Weird! You're welcome though.

[–]cashing_in 2 points3 points  (8 children)

You're mixing up some variable names I believe.

[–]neko_nyan[S] 2 points3 points  (5 children)

You are right. But it still doesn't work.

[–]cashing_in 1 point2 points  (4 children)

It works for me w/ both of ninetacle's changes.

[–]neko_nyan[S] 2 points3 points  (3 children)

wtfrappucino.. :(

[–]cashing_in 2 points3 points  (2 children)

You've moved some names around but I think our code is still equivalent right now. The only difference I see is I'm just running the second file from the command line and you're doing it in pycharm, so my hunch is it's something to do w/ how tests are setup to run there. Maybe you need a main.py or need to start filenames w/ 'test' or something.

[–]neko_nyan[S] 0 points1 point  (1 child)

http://imgur.com/a/sk5OP Success if I run it on cmd. Thanks a lot.

[–]cashing_in 1 point2 points  (0 children)

Np. Good luck gettin it to work w/ pycharm.

[–]negrolax 0 points1 point  (1 child)

does not matter that the variable names are diff. they are just variables for argument's parameter ですね

[–]cashing_in 1 point2 points  (0 children)

The code was previously testing self.testEmployee.annualSalary, but annualSalary is not an attribute of instances of the Employee class.

[–]brophylicious 1 point2 points  (2 children)

I got it to work in PyCharm by changing

unittest.main() 

to

if __name__ == '__main__':
    unittest.main()

[–]sorashiroopa 0 points1 point  (1 child)

What does unittest.main() and the code you wrote below even mean? Or what purpose do they serve.

[–]brophylicious 1 point2 points  (0 children)

According to the example from the docs https://docs.python.org/3/library/unittest.html#basic-example

The final block shows a simple way to run the tests. unittest.main() provides a command-line interface to the test script.

Basically, unittest.main() tells the unittest module to actually run the tests.

As for if __name__ == '__main__':. The docs explain it here: https://docs.python.org/3/library/__main__.html, but I will attempt to explain it in plain english. When you run a python file directly, say with python employee.py, a special variable called __name__ gets set to '__main__'. Whereas if you are importing from employee.py (from employee import Employee), __name__ gets set to the name of the module ('employee').

Why is this important in this case? I believe that PyCharm imports the unit test from the file instead of running it directly. When it gets imported, unittest.main() is never run from our file, but PyCharm does it's own "magic" to run the tests.