Dan*_*oag 5 python testing integration-testing pytest
我正在为一个系统编写集成测试,我可以通过 Web 服务调用自动执行大部分测试,但由于我无法更改遗留问题,我需要手动测试人员完成一些步骤。
\n\n我想使用 pytest 并创建一个夹具,该夹具本质上暂停测试执行并提示控制台输入(例如“在系统中执行 XYZ;完成后键入“完成””)并继续测试的其余部分。
\n\n诚然,我还没有对此进行大量的黑客攻击,但我从 pytest 文档中看到:
\n\n\n\n\n... stdin 设置为 \xe2\x80\x9cnull\xe2\x80\x9d 对象,该对象在尝试读取时会失败,因为在运行自动化测试时很少需要等待交互式输入。
\n
但就我而言,我确实想等待,除此之外,我的东西看起来是 pytest 的一个很好的用例。
\n\n仍在互联网上搜索提示,但如果有人已经克服了这个障碍,我很想知道。
\n从版本 3 开始,您可以暂时禁用捕获:
def test_input(capsys):
with capsys.disabled():
input("hit enter to continue: ")
print("this line is invisible as normal")
Run Code Online (Sandbox Code Playgroud)
给出
(py36) dsm@notebook:~/coding$ py.test -v stdin.py
========================================== test session starts ===========================================
platform linux -- Python 3.6.0, pytest-3.0.7, py-1.4.32, pluggy-0.4.0 -- /home/dsm/sys/miniconda3/envs/py36/bin/python
cachedir: .cache
rootdir: /home/dsm/coding, inifile:
plugins: cov-2.3.1
collected 1 items
stdin.py::test_input hit enter to continue: [here I hit enter]
PASSED
======================================= 1 passed in 23.11 seconds ========================================
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3158 次 |
| 最近记录: |