pytest是一款python测试包,它可以非常轻松地写一些小的,可读的,可扩展的应用代码测试。

安装条件
pytest requires: Python 3.7+ or PyPy3.
安装
pip install -U pytest
简单案例
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
执行方法
pytest test_mod.py
pytest testing/
pytest -k "MyClass and not method"
pytest test_mod.py::test_func
pytest test_mod.py::TestClass::test_method
测试类多个测试方法
# content of test_class.py
class TestClass:
def test_one(self):
x = "this"
assert "h" in x
def test_two(self):
x = "hello"
assert hasattr(x, "check")
网友评论