Python Unittest Import Failure
Im trying to set up my Python3 project to work with test discovery, as described here and covered in this question
My project structure is as follows:
youtube/
youtube/
__init__.py
videos.py
categories.py
test/
test_videos.py
test_categories.py
In my tests I've imported the modules to be tested with their fully qualified names, eg for test_videos.py
my first import is import youtube.videos as videos
.
The problem I'm encountering is that the videos
module imports categories
, and I can't seem to set the import
statement in a way which allows me to run the unit tests and run the __main__
function for videos
.
If I set the import in videos
as import youtube.categories as categories
then unit tests will run fine, but attempting to run the __main__
method raises a ModuleNotFoundError
for youtube
. Conversely, if I leave the import relative, running the unit tests raises a ModuleNotFoundError
on categories
.
Is there any way to resolve this kind of situation without modifying the PYTHONPATH?
链接地址: http://www.djcxy.com/p/54838.html上一篇: IEnumerable的mvc3表单
下一篇: Python单元测试导入失败