python - 在运行 .exe 文件的 pytest 中使用 2 个参数进行参数化测试
问题描述
@pytest.mark.parametrize("x", range(17))
@pytest.mark.parametrize("y", range(11))
def test_foo(x, y)
my_test.exe, my_command 'x' 'y'
我想从“my_test.exe”运行命令“my_command x y”,x 和 y 来自上述范围。
解决方案
实际上,您在参数化调用方面有了一个良好的开端,它的工作原理与此完全一样。您只需要在您的方法中添加流程调用。
一个例子:
import subprocess
import pytest
@pytest.mark.parametrize("x", range(17))
@pytest.mark.parametrize("y", range(11))
def test_foo(x, y):
rc = subprocess.check_call(['/bin/echo', str(x), str(y)])
assert rc == 0
stdout = subprocess.check_output(['/bin/echo', str(x), str(y)])
assert stdout
check_call
或者check_output
程序出错时会引发异常,因此测试失败。您也可以测试输出。
推荐阅读
- python - Django-ajax-selects 与 AJAX_SELECT_BOOTSTRAP = False
- gis - 使用以公里为单位的点数据查找点坐标
- python - 在 Windows 上出现错误“找不到 PyAudio;检查安装”
- reactjs - Redux 将对象添加到数组
- matlab - 在Matlab中(按下左键)?
- jmeter - 希望能够随时间收集延迟和响应时间的指标
- domain-driven-design - 滴滴涕。何时在树状结构中使用聚合根?
- javascript - How to get buttons to disable after a condition has been met?
- php - 有没有办法处理重复的输入?
- facebook - 如何将“publish_pages”权限添加到我的 Facebook 应用程序的 test_user?