要将VS Code设置为使用特定的pytest.ini
文件,您需要执行以下操作:
- 在VS Code(
ctrl+k > ctrl+o
)中打开目录
- 选择 Python解释器(
ctrl+shift+p > Python: Select Interpreter > Python interpreter
)
- 配置您要使用的测试框架,在这种情况下为 PyTest (
ctrl+shift+p > Python: Configure Tests > Pytest > {pytest rootdir}
- 打开在工作目录(您在步骤1中选择的目录)中创建的
settings.json
目录内生成的.vscode/
文件
- 在文件中添加以下设置(如果在配置pytest时指定了
rootdir
,该设置可能已经存在):
"python.testing.pytestArgs": [
"-c","/path/to/your/pytest.ini"
],
就是这样! VS Code应该使用您在最后一个参数中指定的pytest.ini文件。您可以在此处指定任何CLI选项。
Source
,
Pytest要求测试函数名称以test
开头或以test
结尾。
ini文件指示py.test将所有* _test.py文件视为单元测试。
本文链接:https://www.f2er.com/2694005.html