执行下述代码:

1
2
3
4
5
6
7
8
import pytest

@pytest.mark.parametrize('arg',[1])
#测试函数要将argnames做为形参传入
def test_one_params(arg):
print('hello')
print("传入的值为:{}".format(arg))
assert arg == 1

所需命令是:python -m pytest -s test.py

打印结果:

1
2
3
4
5
6
7
8
9
10
11
===================== test session starts =====================
platform win32 -- Python 3.10.8, pytest-7.2.2, pluggy-1.0.0
rootdir: C:\Users\tellw\test
plugins: anyio-3.6.2
collected 1 item

test.py hello
传入的值为:1
.

====================== 1 passed in 0.01s ======================

参考链接:pytest中print的坑

创建于2023.3.9/14.27,修改于2023.3.9/14.27