当前位置:网站首页>Pytest unit test series [v1.0.0] [pytest execute unittest test case]
Pytest unit test series [v1.0.0] [pytest execute unittest test case]
2022-07-06 22:52:00 【Davieyang】
Pytest perform unittest Use cases
unittest Is built on python Unit test framework of standard library , Originally used for testing python Their own , Later, it is also commonly used in unit testing and automated testing of various projects or products , and pytest Can be like unittest Same operation , And can run simultaneously in the same session pytest Use cases and unittest Use cases .
Still Task Project as the tested content , The following code is unittest Use cases under the framework
use pytest Carry out this paragraph unittest Use cases under the framework :
Use unittest Execute this use case :
One more pytest Use cases , As shown in the following code :
use pytest Execute two py file :
Run two separately py file :
The above implementation methods can be carried out smoothly , When we execute at the same time pytest Use cases and unittest Use case , If pytest before , The results are as follows , Just change the order of the two files
use –setup-show Further study
Session wide teardown fixtures It will be executed after all tests , These include unittest The use case , and unittest Inside tearDownModule() The database link has been closed ,pytest Inside tasks_db_sessions() teardown If you do the same thing again, you will fail .
Fix this problem , Can be in unittest Use in pytest Of fixture, As shown in the following code :
Execute use case again :
Here we only need to talk inside pytest and unittest Share resources between , At the same time, you can also pytest markers Use in unittest On , for example @pytest.mark.skip()/@pytest.mark.xfail(), Or customized
However, there is a small problem , stay unittest On the use of pytest.mark.usefixtures, It's not from fixture Pass data directly to unittest function , To achieve this transfer , Can use cls object , As shown in the following code
There is a limitation to using tags : be based on unittest Test cases of cannot be used parametrized Of fixture, The last example uses both pytest fixture and unittest, Reconstitute it pytest The format of test cases is not difficult , Just remove it unittest.TestCase Base class and modify assert You can use it in the same way
Another limitation ,unittest The test subset of stops executing when it first encounters an error , But when used alone unittest when , Whether there is any mistake ,unittest Will run each test subset in turn . Unless all test subsets can pass , otherwise pytest Not all
边栏推荐
- 2022-07-05 use TPCC to conduct sub query test on stonedb
- DockerMySQL无法被宿主机访问的问题解决
- 动作捕捉用于蛇运动分析及蛇形机器人开发
- Const keyword
- Cocoscreator+typescripts write an object pool by themselves
- Self made j-flash burning tool -- QT calls jlinkarm DLL mode
- UDP programming
- 如何实现文字动画效果
- Return keyword
- Gd32f4xx serial port receive interrupt and idle interrupt configuration
猜你喜欢
Clip +json parsing converts the sound in the video into text
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
Cloud native technology container knowledge points
rust知识思维导图xmind
(18) LCD1602 experiment
dockermysql修改root账号密码并赋予权限
How to choose indoor LED display? These five considerations must be taken into account
Mysql 身份认证绕过漏洞(CVE-2012-2122)
Self made j-flash burning tool -- QT calls jlinkarm DLL mode
Aardio - does not declare the method of directly passing float values
随机推荐
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
ICLR 2022 | pre training language model based on anti self attention mechanism
2022-07-05 stonedb sub query processing parsing time analysis
#DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)
How to achieve text animation effect
Sword finger offer question brushing record 1
Inno setup packaging and signing Guide
The statement that allows full table scanning does not seem to take effect set odps sql. allow. fullscan=true; I
uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)
Introduction to network basics
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
【LeetCode】19、 删除链表的倒数第 N 个结点
OpenSSL:适用TLS与SSL协议的全功能工具包,通用加密库
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
[untitled]
Return keyword
DockerMySQL无法被宿主机访问的问题解决
NPM cannot install sharp
Self made j-flash burning tool -- QT calls jlinkarm DLL mode
金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)