python - 使用 Pycharm(IDE) 运行 Pytest

标签 python pycharm pytest

我正在尝试使用 pycharm 运行以下简单测试用例,当我运行这些测试用例时,我看到了输出

Process finished with exit code 0

取而代之的是通过/失败。

我正在运行的测试用例:

import pytest    
from pytest1 import can_p1

msg=0

@pytest.fixture(scope = "module")    
def msgFraming():

    print ("I'm inside FIXTURE")

    nchannel = 686    
    FuncID  = 144    
    opType  = 8        
    FuncID = FuncID * 2    
    msg = nchannel+FuncID+opType

    return msg


def test_cansendMsg(msgFraming):

    res= can_p1.canMsgsend(msg)    
    assert res == msg


def test_canrecvMsg(msgFraming):

    res = can_p1.canMdgrcv(msg)    
    assert res == msg

我在 IDE 中编辑了如下设置:

1)文件->设置->工具->python集成工具->设置默认为py.test

当我运行其他程序(pytest 除外)时,我可以看到 o/p。

最佳答案

  1. 您需要按照 this guide 编辑/创建新配置
  2. 您需要选择 python 测试并在列表中选择 pytest:

choose py.test

  1. 通过选择正确的测试文件和虚拟环境来编辑配置: 检查enter image description here
  2. 应用/保存并运行选定的配置,它应该可以工作 希望这会有所帮助

关于python - 使用 Pycharm(IDE) 运行 Pytest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46529920/

相关文章:

python - 在 Django Admin 中更改密码

python - 在 Python 中打印 csv 文件中选定的列

切换窗口的Vim命令

python - Py.test 收集阶段需要很长时间

python - 编写适用于 ndarray 和 MaskedArray 的通用数值函数的最佳实践

Python 使用 Selenium : how to get the first string in element

pycharm - pycharm持续连接到控制台的原因是什么

python - PyCharm TensorFlow 警告 - 类型 'Variable' 没有预期的属性 '__sub__'

python - pytest 是否支持测试名称中的 unicode?

python-2.7 - 如何使用pytest测试使用数据库连接的python函数?