import pytest
import requests
#定义预期结果:
expect = {"title":"V2EX"}
class TestCase(object):
def test_case_01(self):
assert 1
def test_case_02(self):
assert {"title":"v2ex"} == {"title":"V2EX"}
def xxx_case_01(self):
assert 1
if __name__ == '__main__':
#pytest框架自动收集这个脚本里面所有以test开头当成测试用例执行里面的代码
pytest.main(["-s","run测试用例类的写法.py"]) #高版本以列表写法
# pytest.main("-s run测试用例类的写法.py") #低版本写法
"""
结果:
============================= test session starts =============================
platform win32 -- Python 3.6.6, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: D:s27day68
collected 2 items(收集到两个测试用例)
run测试用例类的写法.py .(一个成功)F(一个失败)
================================== FAILURES(失败信息如下) ===================================
____________________________ TestCase.test_case_02 ____________________________
self = <run测试用例类的写法.TestCase object at 0x0000000003A572B0>
def test_case_02(self):
> assert 0
E assert 0(失败答复)
run测试用例类的写法.py:14: AssertionError
========================= 1 failed, 1 passed in 0.39s =========================
"""