1

This is probably a noob problem. For that I apologize, but I couldn't find a solution so far. I short, for some reason that I don't understand, I can't access modules from my src directory in my tests. My project setup looks like this:

src/package/module.py
tests/package/module_test.py

and my test roughly looks like this:

import package
import unittest
class module_test(TestCase):
   def testSomeMethod(self):
       m = package.SomeClass() #there is class of that name in module.py

I checked the run configuration setup in PyDev and it says that both src and tests are on the PYTHONPATH when I execute the tests. But when I try to run this test, I get the error 'module' object has no attribute 'SomeClass'.

What am I doing wrong?

1 Answer 1

1

When you do import package, you import the package, not the module inside it. If you want to import the module, you need to do from package import module (and then refer to the class as module.SomeClass, not package.SomeClass).

Packages are containers for groups of modules. They don't magically allow you to access everything inside any of the modules (although you can have them automatically import their modules). You still have to import the individual modules in the package.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.