python - 创建 pytest 插件
问题描述
我使用 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
但是,我的 conftest.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')
解决方案
推荐阅读
- excel - Microsoft ACE 文本驱动程序将数字转换为日期
- linux - tr 的意外输出
- javascript - 未处理的承诺拒绝类型错误:对象不支持属性或方法“getAsync”
- python - 尝试使用 python 抓取网站时出错
- php - preg_replace_callback_array 不返回匹配计算值
- react-native - 任何混合应用程序中的多语言 I18n
- linux - 如何使用单个 linux 命令创建带有子文件夹的新文件夹?
- python - Python函数将二进制数字转换为十六进制
- javascript - 如何从复选框中获取选中的值(值)并使用 Angular 保存到数据库中
- javascript - 以毫秒为单位反应本机倒计时计时器