"TypeError: 'module' object is not callable" when running with py.test under /test folder
Question: I have a class `Foo` which lives in `Src/Projects/SomeProject/Foo.py`

I have a class `FooTest(unittest.TestCase)` which lives in:

    
    
    Src/Projects/SomeProject/tests/FooTest.py
    

When I run it with pytest (I just type 'py.test' in Src to run all tests), I
get:

    
    
     def setUp(self):
         self.foo = Foo()
         TypeError: 'module' object is not callable
    

(I have `from Foo import Foo` in `FooTest.py` and `Foo.py` is in `sys.path`.

But when I run it with python: `python
Src/Projects/SomeProject/tests/FooTest.py` everything works.)

Also, if I just move FooTest.py to `Src/Projects/SomeProject` then running
with py.test suddenly works.

Any ideas?


Answer: You need to check your python path; some other `Foo.Foo` is being found before
your module `Foo`.

Alternatively, in a `try`/`except TypeError` suite, print out the path of the
offending module:

    
    
    def setUp(self):
        try:
            self.foo = Foo()
        except TypeError:
            # What module Foo is this?
            print Foo.__file__
            raise
    

