我使用pytest对代码进行单元测试。关于这一点,我试图创建一个可以在我的目录中使用的pytest插件。我可以在主根目录中创建一个conftest.py文件,或者创建一个可安装的pytest插件。我更喜欢第二种选择
然而,pytest文档确实为如何继续创建和安装用户定义的插件提供了很好的指导。我在父目录中创建了setup.py,该目录是我的conftest.py所在的目录。我的setup.py如下所示:
from setuptools import setup
setup(
name="tryplugin",
packages = ['pluginTry'],
version = "1.0.0",
# the following makes a plugin available to pytest
entry_points = {
'pytest11': [
'name_of_plugin = pluginTry',
]
},
classifiers=["Framework :: Pytest"],
)
接下来,我运行命令:
python3 setup.py install
我的插件随后出现在pytest list
但是,myconftest.py创建的命令行pytest选项不会出现在pytest -h
中。我的固定装置也没有出现pytest --fixtures
相反,我得到了以下错误:
During handling of the above exception, another exception occurred:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py/_path/local.py:718: in pyimport
issame = self.samefile(modfile)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py/_path/local.py:204: in samefile
return py.error.checked_call(
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py/_error.py:86: in checked_call
raise cls("%s%r" % (func.__name__, args))
E py.error.ENOTDIR: [Not a directory]: samefile('/Users/myName/Desktop/MainDirectory/pluginTry/conftest.py', '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/tryplugin-1.0.0-py3.8.egg/pluginTry/conftest.py')
目前没有回答
相关问题 更多 >
编程相关推荐