The pytest of online learning python started to run and there was a problem
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")
Error message
TypeError: `args` parameter expected to be a list of strings, got: '-s' (type: <class 'str'>)
Solution Method of
modifying parameters: 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"])