当前位置:网站首页>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
边栏推荐
猜你喜欢

修改mysql的分组报错Expression #1 of SELECT list is not in GROUP

【专栏】RPC系列(理论)-夜的第一章

Angr(八)——angr_ctf

File upload function

message from server: “Host ‘xxx.xxx.xxx.xxx‘ is not allowed to connect to this MySQL server“

切换 shell 命令行终端(bash/zsh)后,conda 无法使用: command not found

js加密参数定位
构建 Dompteur 容器问题小记

Pow(x,n)

IDEA整体字体大小修改
随机推荐
一、unittest框架和pytest框架的区别
Leetcode 560 前缀和+哈希表
用户喜好
Oh my Zsh and TMUX configuration (personal)
Radio and multi selection buttons of swing components
IO流中的输出流
Angr (IV) -- angr_ ctf
Ansible Deployment Guide
Principle of struct2
Use and principle of rest
@Import,Conditional和@ImportResourse注解
多线程——死锁和synchronized
鼠标监听,画笔
Simple addition calculator
Virtual private line network deployment
存储、计算、分布式虚拟化篇(收集整理适合小白)
集合的创建,及常用方法
部署主从数据库
Number theory --- the greatest common divisor and the least common multiple
Detailed explanation of chrome developer tools