标签:tar pass error: 并且 HERE 识别 ref self __name__
pytest与python自带的unittest测试框架类型,但是pytest使用起来更简洁高效。
pytest支持315种以上的插件,可以访问网址:http://plugincompat.herokuapp.com/
pytest帮助文档地址:https://docs.pytest.ort/
pip install -U pytest
查看版本
pytest --version
用例的编写规范
实例
test_001.py
import pytest
def add(a, b):
return a + b
def test_add():
assert add(1, 2) == 3
assert add(1, 1) == 2
assert add(1, 99) == 100
class TestAdd:
astr = "pytest"
def test_01(self):
assert "y" in self.astr
def test_02(self):
assert hasattr(self.astr, "check")
if __name__ == ‘__main__‘:
pytest.main(["-s"])
结果
"D:\Program Files\Python36-32\python.exe" D:/git/test/test_pytest.py
============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-5.4.2, py-1.8.1, pluggy-0.13.1
rootdir: D:\git\test
plugins: allure-pytest-2.8.16
collected 3 items
test_pytest.py ..F
================================== FAILURES ===================================
_______________________________ TestAdd.test_02 _______________________________
self = <test_pytest.TestAdd object at 0x03EB6930>
def test_02(self):
> assert hasattr(self.astr, "check")
E AssertionError: assert False
E + where False = hasattr(‘pytest‘, ‘check‘)
E + where ‘pytest‘ = <test_pytest.TestAdd object at 0x03EB6930>.astr
test_pytest.py:26: AssertionError
=========================== short test summary info ===========================
FAILED test_pytest.py::TestAdd::test_02 - AssertionError: assert False
========================= 1 failed, 2 passed in 0.10s =========================
进程已结束,退出代码 0
标签:tar pass error: 并且 HERE 识别 ref self __name__
原文地址:https://www.cnblogs.com/zhsp/p/13286142.html