有两种执行方式
第一种
测试内容例子如下
import pytest
def func(x):
return x+1
def test_answer():
assert func(3) == 5
创建好.py的文件之后,再命令行中进入到该文件的所在路径,执行命令
py.test -q 文件名.py
第二种
创建文件的时候在main函数中设置好参数和被执行的py文件,如下所示
import pytest
class TestClass:
def test_one(self):
print('one')
x = 'this'
assert 'h' in x
def test_two(self):
print('two')
x = 'hello'
assert hasattr(x,'check')
if __name__ == '__main__':
pytest.main(args=['文件名.py','-q','--html=a.html'])
同样在命令行进到该文件目录下,执行命令
python 文件名.py