当前位置:网站首页>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
边栏推荐
- Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
- C# 三种方式实现Socket数据接收
- Custom swap function
- Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
- 欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
- Traversal of a tree in first order, middle order, and then order
- European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
- Jafka source analysis processor
- 存币生息理财dapp系统开发案例演示
- MATLAB小技巧(27)灰色预测
猜你喜欢

企业不想换掉用了十年的老系统

(18) LCD1602 experiment

Cocoscreator+typescripts write an object pool by themselves

UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop

MySQL authentication bypass vulnerability (cve-2012-2122)

室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内

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

Pit encountered by handwritten ABA

Mysql 身份认证绕过漏洞(CVE-2012-2122)

【LeetCode】19、 删除链表的倒数第 N 个结点
随机推荐
机试刷题1
第十九章 使用工作队列管理器(二)
允许全表扫描 那个语句好像不生效set odps.sql.allow.fullscan=true;我
Cloud native technology container knowledge points
Gd32f4xx serial port receive interrupt and idle interrupt configuration
Config:invalid signature solution and troubleshooting details
Some suggestions for foreign lead2022 in the second half of the year
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
云原生技术--- 容器知识点
监控界的最强王者,没有之一!
Puppeter connects to the existing Chrome browser
Web APIs DOM time object
做国外LEAD2022年下半年几点建议
UVa 11732 – strcmp() Anyone?
NPM cannot install sharp
BasicVSR_ Plusplus master test videos and pictures
How to choose indoor LED display? These five considerations must be taken into account
ICLR 2022 | pre training language model based on anti self attention mechanism
Sword finger offer question brushing record 1