当前位置:网站首页>1、 The difference between unittest framework and pytest framework
1、 The difference between unittest framework and pytest framework
2022-07-25 10:21:00 【Christmas gift box】
1. Use case writing rules
unittest: Provides testcase The test case 、testsuite test suite 、testfixture Test firmware or fixture 、testloader Test loader 、testrunner Test runner . The following rules must be observed :
(1) Test files must be imported first import unittest
(2) The test class must inherit unittest.TestCase
(3) The test method must be test start
pytest: It is python Third party testing framework for , be based on unittest The extension framework of , The following rules must be observed :
(1) The test file name must be test_ Beginning or _test ending
(2) Test class commands must start with Test start
(3) The test method must be test start
2. Pre and post use cases
unittest:
setUp/tearDown Run once before or after each use case
Open the browser , Load web page / Close page
setUpClass and tearDownClass Run once before or after each class
Create database connection , Create a log object / Close database connection , Destroy log object
setUpModule and tearDownModule Run once before and after each door module
pytest:
Method level :
setup_mmothod/teardown_mothod Before and after the method
setup/teardown
Function level :
setup_function/teardown_function Before and after the function
Class level :
setup_class/teardown_class Before and after the class
Module level :
setup_module/teardown_module Before and after the module
also : You can also add... Before the function @pytest.fixture() Decorator
3. Assertion
unittest:assertTure、assertEqual、assertln
pyutest:assert
4. The report
unittest:htmltestrunner
pytest: plug-in unit :pytest-HTML,allure
5. Fail to run again
unittest: No,
pytest:pytest-rerunfailures plug-in unit
6. Data driven
unittest:ddt
pytest:@pytest.mark.parametrize Decorator
7. Use case classification execution
unittest: By default, all , It can also be done through testsuite To execute some use cases , perhaps -k Parameters
pytest:@pytest.mark
边栏推荐
猜你喜欢
随机推荐
广度优先遍历(图和二叉树的层序遍历相关问题)
IO流中的输出流
Yiwen society, three necessary packet capturing tools for hackers
Radio and multi selection buttons of swing components
Virtual private line network deployment
Copy the old project into a web project
Angr(七)——angr_ctf
集合的创建,及常用方法
常用类的小知识
Open virtual private line network load balancing
Ansible Deployment Guide
IDEA整体字体大小修改
Ubuntu20.04系统下安装MySQL数据库5.7.29版本
Use of dictionary tree
MySQL solves the problem of not supporting Chinese
将 conda 虚拟环境 env 加入 jupyter kernel
配置FTP虚拟用户及访问控制
Chrome开发者工具详解
【专栏】RPC系列(理论)-夜的第一章
Erlang(离线部署)








