Skip to content Skip to sidebar Skip to footer

Unit Tests Not Importing Project Modules (python)

My code structure is: + project | + - - project_code | | __init__.py | \ main.py | + - - test | __init__.py \ test_main.py In my test_main.py I have: import

Solution 1:

Put an empty __init__.py in your project folder to make it a package and then either change your code to

import unittest
from project.project_code.mainimportMainClass

or do it the relative way with

import unittest
from ..project_code.mainimportMainClass

Your test_main in package test, will not find a module or package named project_code, because it expects it to be inside the test package.

Post a Comment for "Unit Tests Not Importing Project Modules (python)"