Nosetest initialization error

the call 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 things.

My directory structure looks like this:

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 doesn't give me an indication of where in my code the error occurred. Any ideas on how I can find it? The best I can think of is getting rid of all the test files and then putting them one by one, but this is not entirely ideal.

+3


source to share


3 answers


Decision:

remove import statements from the top of the script.

Why:

After posting the test file that gave me problems, I followed through nosetests

with the option -vv

as suggested by Evert. It turned out that the error message was not coming from any particular test. That is, the tests ran as expected, these errors were simply flagged in the output. The result looked something like this:

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 translated them to where they were used.

But why does this happen? Bonus points to anyone who knows



again, I don't feel like reading through the codes 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

      

The error is 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

      

+1


source


The usual reason for this is that you are using a class in one of those tests that are not imported in it, or that imports have been corrupted in it. Or otherwise, there is an individually broken test or imported class that, when initialized with other tests through the global wait environment of the validation test script, ends up, for example, due to the lack of imported imports in another test. But on bootstrapping a test class or loading it separately - this will raise a not found or other error. But the nose doesn't make it very clear, although it probably does show an initialization error for the class.

So, using your sample code in a test environment, something in the "goodies" is not passed an argument when initializing the module, which is required to initialize properly. But it gets it if it gets initialized later in tests.



Alternatively, you have a method accidentally called test_something in a class that is not intended for the test class (like somewhere in the goodies or the class it uses) and nose finds and initializes it without the required parameters.

You can try going through the imports one by one, bringing them back to the module level and then initializing the problem class in the python shell to fix it.

+3


source


So I wasted too much time on this problem and want to return.

If you run nosetests with --with-xunit

, you will notice that checking for a bug is booked along the way nose.failure.Failure.runTest

. If you try to run this test, it says it doesn't exist. There is something strange here.

I wonder if you run it under --collect-only --verbose

you get Failure: TypeError (__init__() takes exactly 2 arguments (1 given)) ... ok

, so something is recognized as a test first when it probably shouldn't, and secondly, it doesn't fire immediately. Evily, the two packages adjacent to the failing test go through in such a way that even figuring out which file is failing is not straightforward.

As it turned out, a nettest file was created there, which had test

in its name. The nose tried to interpret it as a test and therefore an error.

Unfortunately I had to manually run each package to figure it out. One way to do this is find /path/to/package -name "*test*.py

and then grep for anything that doesn't live in the tests directory.

0


source







All Articles