01-pytest-安装及入门

 

目录

 

1.安装

2.查看版本

3.创建第一个测试

                  4.pytest用例规则


1.安装

pip install -U pytest

2.查看版本

pytest --version
# 或
pip show pytest

3.创建第一个测试

1.新建test_sample.py

def func(x):
    return x + 1


def test_answer():
    assert func(3) == 5

 2.命令行执行,切到文件所在目录,执行pytest,结果如下:

01-pytest-安装及入门_第1张图片

3.pytest运行规则:当前目录及其子目录中运行所有格式为test _ *.py或*_test.py

 

4.pytest用例规则

  • 测试文件以test_开头(以_test结尾也可以)
  • 测试类以Test开头,并且不能带有 __init__ 方法
  • 测试函数以test_开头
  • 断言使用assert

你可能感兴趣的:(pytest,python)