深圳附近做个商城网站多少钱,做防腐木花架的网站,中国最牛的央企排名,合川网站制作从一个或多个目录开始查找#xff0c;可以在命令行指定文件名或目录名。如果未指定#xff0c;则使用当前目录。 测试文件以 test_ 开头或以 _test 结尾 测试类以 Test 开头 #xff0c;并且不能带有 init 方法 测试函数以 test_ 开头 断言使用基本的 assert 即可 所有的… 从一个或多个目录开始查找可以在命令行指定文件名或目录名。如果未指定则使用当前目录。 测试文件以 test_ 开头或以 _test 结尾 测试类以 Test 开头 并且不能带有 init 方法 测试函数以 test_ 开头 断言使用基本的 assert 即可 所有的包 pakage 必须要有__init__.py 文件 # test_2.py
import sysimport pytestdef add(x,y):return x ypytest.mark.add
def test_add():assert add(1,2) 3assert add(2,3) 5assert add(10,2) 12def is_win32():return True if sys.platform win32 else Falseclass TestDemo:def test_demo(self):x hello worldprint(f{x} python)assert h in xpytest.mark.skipif(sys.platform win32,reasonwin32跳过用例)def test_demo3(self):x hello worldprint(f{x} python)assert h in xonly_win32 pytest.mark.skipif(is_win32(),reasonwin32跳过用例)only_win32def test_demo4(self):x hello worldprint(f{x} python)assert h in xpytest.mark.skip(变更)def test_demo2(self):x helloassert hasattr(x,check)pytest.mark.xfail(reasonbug待修复)def test_demo5(self):x helloassert hasattr(x, check)if __name__ __main__:pytest.main([-v, -s])
1执行全部
if name __main__: pytest.main([-v, -s]) 2执行某个文件
if name __main__: pytest.main([-v, -s,test_2.py]) 3执行某个类
if name __main__: pytest.main([-v, -s,test_2.py::TestDemo]) 4 执行某个方法
if name __main__: pytest.main([-v, -s,test_2.py::TestDemo::test_demo]) 5 mark 打标执行 pytest.mark.add 6 skip忽略执行 pytest.mark.skip(变更) 7 条件忽略skipif pytest.mark.skipif(sys.platform win32,reasonwin32跳过用例) 8xfail预期失败 pytest.mark.xfail
真失败会显示xfailed成功会显示xpassed,应用场景已知bug标注后续验证修复