如何让 PyCharm 从由 PyScaffold 创建的 setup.cfg 中获取测试配置? [英] How do I make PyCharm take the testing configuration from setup.cfg, which was created by PyScaffold?
问题描述
如何让 PyCharm 从 setup.cfg(PyScaffold 创建的文件)中获取测试配置?
How do I make PyCharm take the testing configuration from setup.cfg, a file which was created by PyScaffold?
我确实从设置 -> 工具 -> Python 集成工具 -> 测试启用了 PyTest
I did enable PyTest from Settings -> Tools -> Python Integrated Tools -> Testing
到目前为止,我拥有的是保存在 Python 测试部分的配置,包括:
What I have until now is a configuration saved in the Python tests section, with:
目标:脚本路径 = C:...\setup.py
Target: Script path = C:...\setup.py
附加参数:测试
但这就是我运行它时得到的:
But this is what I'm getting when I run it:
[...] ERROR: file not found: test
<小时>
或者如何在 PyCharm 中复制与 setup.cfg 中相同的测试配置?
Or how do I replicate the same testing configuration in PyCharm, as I have in setup.cfg?
console_scripts =
program = program.main:run
[test]
# py.test options when running `python setup.py test`
# addopts = --verbose
extras = True
[tool:pytest]
# Options for py.test:
# Specify command line options as you would do when invoking py.test directly.
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
# in order to write a coverage file that can be read by Jenkins.
addopts =
--cov reddit_users_info --cov-report term-missing
--verbose
[...]
testpaths = tests
推荐答案
打开项目目录并将其配置为使用创建的 venv.在脚本路径中,您将拥有
src\program\program.py
,在参数处,您可以添加-vv
.
Open the project directory and configure it to use the venv created. At script path you would have
src\program\program.py
, at parameters you could add-vv
.
从 Settings -> 启用 PyTest工具 ->Python 集成工具 ->测试
添加一个运行配置,但也添加一个用于测试:Edit Configurations ->+ ->Python 测试 ->pytest
.
Add a run configuration, but add one for testing as well: Edit Configurations -> + -> Python tests -> pytest
.
运行测试.如果您已经安装了测试所需的软件包,它将起作用(检查上面的测试"部分).该过程将在项目目录中创建一个 .coverage 文件.
Run the tests. It will work if you've installed the packages required for testing (check the above "To test" section). The process will create a .coverage file in the project directory.
如果你有 PyCharm Professional 而不是 PyCharm Community,你也应该这样做:
If you have PyCharm Professional instead of PyCharm Community, you should also do this:
Ctrl + Alt + F6(选择要显示的覆盖套件)->+ ->选择任何创建的文件 ->显示选中的
.这将在您的脚本中添加花哨的颜色,具体取决于测试覆盖的代码位置.
Ctrl + Alt + F6 (Choose coverage suite to display) -> + -> select any of the created files -> Show selected
.
This will add fancy colors in your scripts, depending on where the code is covered by tests.
这篇关于如何让 PyCharm 从由 PyScaffold 创建的 setup.cfg 中获取测试配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!