解决 TypeError: `args` parameter expected to be a list of strings, got: ‘-s‘ (type: <class ‘str‘>)

网上学习python 的 pytest 开始运行出现了问题

import pytest # 引入pytest包
def test_a(): # test开头的测试函数
    print("------->test_a")
    assert 1 # 断言成功
def test_b():
    print("------->test_b")
    assert 0 # 断言失败
if __name__ == '__main__':
    pytest.main("-s  test_abc.py")

报错信息

TypeError: `args` parameter expected to be a list of strings, got: '-s' (type: <class 'str'>)

解决办法
修改参数方法: pytest.main(["-s",“test_abc.py”])


import pytest # 引入pytest包
def test_a(): # test开头的测试函数
    print("------->test_a")
    assert 1 # 断言成功
def test_b():
    print("------->test_b")
    assert 0 # 断言失败
if __name__ == '__main__':
	# 参数改为列表,列表中以字符串方式放入需要参数
    pytest.main(["-s","test_abc.py"])

猜你喜欢

转载自blog.csdn.net/weixin_45598506/article/details/114259731