当前位置:网站首页>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
边栏推荐
- ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
- Introduction to network basics
- 做国外LEAD2022年下半年几点建议
- 动作捕捉用于蛇运动分析及蛇形机器人开发
- Windows Auzre 微软的云计算产品的后台操作界面
- ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
- Pit encountered by handwritten ABA
- Void keyword
- Let's see through the network i/o model from beginning to end
- Return keyword
猜你喜欢

【LeetCode】19、 删除链表的倒数第 N 个结点

MySQL ---- first acquaintance with MySQL

Machine test question 1

Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi

自定义 swap 函数

Let's see through the network i/o model from beginning to end

Cocoscreator+typescripts write an object pool by themselves

cuda 探索

Export MySQL table data in pure mode

Advantages of link local address in IPv6
随机推荐
MySQL ---- first acquaintance with MySQL
[leetcode] 19. Delete the penultimate node of the linked list
Rust knowledge mind map XMIND
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
ICLR 2022 | pre training language model based on anti self attention mechanism
Enterprises do not want to replace the old system that has been used for ten years
MySQL教程的天花板,收藏好,慢慢看
How to achieve text animation effect
DockerMySQL无法被宿主机访问的问题解决
2022-07-05 stonedb sub query processing parsing time analysis
Cocoscreator+typescripts write an object pool by themselves
【编译原理】做了一半的LR(0)分析器
Chapter 19 using work queue manager (2)
Puppeter connects to the existing Chrome browser
POJ 1094 sorting it all out
Method of canceling automatic watermarking of uploaded pictures by CSDN
Pit encountered by handwritten ABA
Redis 持久化机制
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi