My code executes correctly using python3, but using coverage3 returns an ImportError when importing a package I created.
My project looks as follows:
components/common/ConfigTest/ConfigTest.py -> file I want to execute - a test for the Config class declared in Config.py
components/common/Config.py -> file included in ConfigTest.py
The environment variable PYTHONPATH points to the location of the components directory so I can use it as base directory for my imports.
The ConfigTest.py file starts as follows:
import os
import unittest
from common.Config import Config
While located in the ConfigTest directory, running the following command produces the expected output:
python3 -m unittest ConfigTest.py
However, either running coverage3 run ConfigTest.py or coverage3 run -m unittest ConfigTest.py produce the following error:
Traceback (most recent call last):
File "ConfigTest.py", line 7, in <module>
from common.Config import Config
ImportError: No module named 'common.Config'
In the past I experienced similar problems when executing my code on different machines/different versions of Python, and these problems were caused due to the wrong setup of the PYTHONPATH environment var. In this case, I printed print(os.environ['PYTHONPATH']) before doing the problematic import, and it prints the correct value of such var when using python3 and coverage3.
Any clue on what the problem could be? Thanks.
import sys print sys.executable print "\n".join(sys.path)add this inside ConfigTest.py on the top and see the path of the python that is being invoked.