py.test can't import my module

帅比萌擦擦* 提交于 2019-12-05 09:09:06

First, unless you change the tests/test_testclass.py, you need to change module/__init__.py as follow:

from .testclass import TestClass

__all__ = ['TestClass']

And, when you run py.test set PYTHONPATH environment variable to let the interpreter know when to find modules:

PYTHONPATH=. py.test

I would put in a header of testfile the path execution for pytest:

example:

import os, sys                                                                  
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))

With this I could know the path of any subfolder in my (test) project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!