从pycharm运行pytest时获取空的测试套件

时间:2018-03-19 16:26:46

标签: python-3.x pycharm

我在PyCharm中运行pytest测试时遇到问题

我在C:\ Temp中名为agents_automation_2的文件夹中有一个文件x_tests.py,该文件的内容为

import pytest
def test_mytest():
    assert  False

当我跑步时,我得到以下输出

C:\ Python36-32 \ python.exe" C:\ Program Files \ JetBrains \ PyCharm 2017.3.2 \ helpers \ pycharm_jb_pytest_runner.py" --path C:/ Temp / agents_automation_2 在C:\ Temp \ agents_automation_2中使用参数C:/ Temp / agents_automation_2启动py.test =============================测试会话开始================== =========== 平台win32 - Python 3.6.4,pytest-3.4.2,py-1.5.2,pluggy-0.6.0 rootdir:C:\ Temp \ agents_automation_2,inifile: 插件:xdist-1.22.0,forked-0.2 收集了0件物品 ========================没有测试在0.01秒内运行==================== =====

但是,当我从文件夹内的常规Windows命令行运行时,测试运行正常

知道可能出现什么问题?

谢谢!!!

4 个答案:

答案 0 :(得分:3)

测试文件的名称不符合默认的pytest发现规则。如果您将 x_tests.py 更改为 x_test.py ,则会运行测试并按预期失败。有关pytest发现规则的更多信息,请查看this page

答案 1 :(得分:0)

确保 PyCharm 配置为使用 PyTest。默认情况下,它使用单元测试。查看此文档:https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html。正确配置 PyCharm 以使用 PyTest 后,例如,当您打开测试文件的上下文菜单时,您将看到类似 Run 'PyTest in ... '

答案 2 :(得分:0)

就我而言,我只需要从项目中删除 pytest.ini 文件。

答案 3 :(得分:0)

对于使用 WSL 的用户,问题可能与 WSL 无法访问有关。 如果您在 WSL 上遇到此错误,

Logon failure: the user has not been granted the requested logon type at this computer.

尝试在 PowerShell 中重新启动 vmcompute 服务(以管理员身份运行):

powershell restart-service vmcompute

来源:https://github.com/microsoft/WSL/issues/5401