01-pytest-安装及入门

简介: 01-pytest-安装及入门

1.安装

pip install -U pytest

2.查看版本

1. pytest --version
2. # 或
3. pip show pytest

3.创建第一个测试

1.新建test_sample.py

1. def func(x):
2. return x + 1
5. def test_answer():
6. assert func(3) == 5

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

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

 

4.pytest用例规则

  • 测试文件以test_开头(以_test结尾也可以)
  • 测试类以Test开头,并且不能带有 __init__ 方法
  • 测试函数以test_开头
  • 断言使用assert
相关文章
|
1月前
|
数据可视化 测试技术 持续交付
自动化测试神器:Python之Pytest库入门使用
自动化测试神器:Python之Pytest库入门使用
114 4
|
1月前
|
测试技术 API Python
Python自动化测试:unittest与pytest的实战技巧
Python自动化测试:unittest与pytest的实战技巧
|
1月前
|
jenkins 测试技术 持续交付
pytest教程-1-环境搭建
Pytest是Python的一种单元测试框架,与Python自带的unittest测试框架类似,但是比 unittest框架使用起来更简洁,效率更高。
|
10月前
|
测试技术
Pytest-插件介绍与使用
Pytest-插件介绍与使用
40 1
|
11月前
|
JSON 测试技术 数据格式
19-pytest-allure-pytest环境搭建
19-pytest-allure-pytest环境搭建
|
测试技术 数据库 Python
Python单测框架Pytest教程
The pytest framework makes it easy to write small, readable tests, and can scale to support complex functional testing for applications and libraries. pytest介绍和教程。 pytest 框架使编写小型可读测试变得容易,并且可以扩展以支持应用程序和库的复杂功能测试。
141 0
|
自然语言处理 Java 测试技术
pytest学习和使用21-测试报告插件allure-pytest如何使用?
pytest学习和使用21-测试报告插件allure-pytest如何使用?
133 0
pytest学习和使用21-测试报告插件allure-pytest如何使用?
|
负载均衡 监控 测试技术
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
161 0
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
|
Python Windows
pytest 框架环境搭建
pytest 框架环境搭建
364 0
|
Linux 测试技术 Python
pytest学习和使用1-pytest安装和版本查看
pytest学习和使用1-pytest安装和版本查看
422 0
pytest学习和使用1-pytest安装和版本查看