Issue
I have the following project structure:
v/b.py
v/e.py
v/e_test.py
v/p.py
v/__init__.py
#v/e.py
from b import B
from p import P
class E(object):
def run(self): pass
#v/p.py
class P(object):
def run(self): pass
#v/b.py
from p import P
class B(object):
def run(self): pass
#v/e_test.py
from e import E
import unittest
class ETest(unittest.Testcase):
def testSomething(self): pass
if __name__ == '__main__':
unittest.main()
Then I run this pip3 install coverage
.
Then coverage run e_test.py
It's giving me this error
Traceback (most recent call last):
File "e_test.py", line 4, in <module>
from e import E
File "~/v/e.py", line 1, in <module>
from b import B
File "~/v/b.py", line 1, in <module>
from p import P
ImportError: cannot import name 'P' from 'p' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/p.py)
My question now is how to fix this. Also I want to be able to run:
- coverage run e_test.py b_test.py files_test.py
- python3 e_test.py
- python3 e.py
Solution
At last I found the answer. If I'm in the parent folder which contains the v folder, I can run the following command.
PYTHONPATH=./v:$PYTHONPATH coverage run -m unittest discover -s v -p "*_test.py"
or without coverage
PYTHONPATH=./v:$PYTHONPATH python3 -m unittest discover -s v -p "*_test.py"
If I'm inside the v folder, I can run
python3 e.py
and
python3 e_test.py
Answered By - TrongBang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.