如何使PyCharm从setup.cfg中获取测试配置,该配置由PyScaffold创建?

时间:2018-12-30 22:19:45

标签: python python-3.x pycharm

我如何让PyCharm从setup.cfg(由PyScaffold创建的文件)中获取测试配置?

我确实通过设置->工具-> Python集成工具->测试启用了PyTest


到目前为止,我所拥有的配置保存在Python测试部分中,其中包含:

目标:脚本路径= C:... \ setup.py

其他参数:测试


但这是我运行它时得到的:

[...] ERROR: file not found: test

或者如何像在setup.cfg中一样在PyCharm中复制相同的测试配置?

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

1 个答案:

答案 0 :(得分:2)

  1. 打开项目目录,并将其配置为使用创建的venv。在脚本路径中,您将有src\program\program.py, 您可以在参数中添加-vv

  2. Settings -> Tools -> Python Integrated Tools -> Testing启用PyTest

  3. 添加一个运行配置,但还要添加一个用于测试的配置:Edit Configurations -> + -> Python tests -> pytest

  4. 运行测试。如果您已经安装了测试所需的软件包,它将起作用(请检查上面的“测试”部分)。 该过程将在项目目录中创建一个.coverage文件。

  5. 如果您拥有PyCharm Professional而不是PyCharm Community,则还应该这样做:

Ctrl + Alt + F6 (Choose coverage suite to display) -> + -> select any of the created files -> Show selected。 这将在脚本中添加奇特的颜色,具体取决于测试覆盖的代码。