I have a very simple question about Python and unittest.
I have such a directory structure.
Project
|
|-lib
|
|-__init__.py
|-class.py
|
|-tests
|
|-__init__.py
|-test_class.py
Now this is my test_class.py content. If I import lib.class from the root folder, it works fine. But if I import the file from another place, it does not work.
import unittest
from lib.class import Class
class TestClass(unittest.TestCase):
def testClass(self):
// do some test
def main():
unittest.main()
if __name__ == '__main__':
main()
When I run the test, I got this error
Traceback (most recent call last):
File "tests/test_class.py", line 2, in
from lib.class import Class
ImportError: No module named lib.class
I donβt know how to import a file from another folder, and not to the root folder.
source
share