calling nosetests
gives me the following:
======================================================================
ERROR: Failure: TypeError (__init__() takes exactly 2 arguments (1 given))
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/sheena/WORK/CriticalID/workspace/flow_env2/local/lib/python2.7/site-packages/nose-1.3.4-py2.7.egg/nose/loader.py", line 519, in makeTest
return self._makeTest(obj, parent)
File "/home/sheena/WORK/CriticalID/workspace/flow_env2/local/lib/python2.7/site-packages/nose-1.3.4-py2.7.egg/nose/loader.py", line 578, in _makeTest
return MethodTestCase(obj)
File "/home/sheena/WORK/CriticalID/workspace/flow_env2/local/lib/python2.7/site-packages/nose-1.3.4-py2.7.egg/nose/case.py", line 345, in __init__
self.inst = self.cls()
TypeError: __init__() takes exactly 2 arguments (1 given)
as well as some other stuff.
My directory structure looks like:
MyStuff
./__init__.py
./tests
./some_tests.py
./other_tests.py
./ ... lots more
./a_useful_group_of_tests
./more_tests.py
./tasty_tests.py
./ ...lots more
./other_files_and_directories
Now there are a lot of tests in a lot of files and this error gives me no indication of where in my code the error came from. Any ideas about how I can find it? The best I can come up with so far is to get rid of all the test files and then put them back one by one but that is not exactly ideal.
The solution:
remove import statements from the top of the script.
Why:
After locating the test file giving me issues I executed nosetests
with the -vv
option as per Evert's suggestion. It turned out that the error message wasn't coming from any specific test. Ie, the tests were running as expected, those errors were just tagged onto the output. The output looked something like:
Failure: TypeError (__init__() takes exactly 2 arguments (1 given)) ... ERROR
Failure: TypeError (__init__() takes exactly 2 arguments (1 given)) ... ERROR
...
test_clear_instructions (the_calculator2.tests.model_tests.workflow_tests.Workflow_tests) ...
...all my tests follow
The only things not in test cases were import statements. So I just moved them to where they were used.
But why would this happen? Bonus points to anyone who knows
again, I dont feel like reading through reams of code to find the answer
Illustrative code:
from my.stuff import goodies #<----------Error from this line
class My_tests(unittest.TestCase):
def test_one(self):
do stuff
def test_two(self):
do other stuff
No error in this code:
class My_tests(unittest.TestCase):
def test_one(self):
from my.stuff import goodies
do stuff
def test_two(self):
from my.stuff import goodies
do other stuff