当前位置:网站首页>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
边栏推荐
- poj 1094 Sorting It All Out (拓扑排序)
- three.js绚烂的气泡效果
- OpenSSL: a full-featured toolkit for TLS and SSL protocols, and a general encryption library
- Sizeof keyword
- CSDN 上传图片取消自动加水印的方法
- 【无标题】
- Chapter 19 using work queue manager (2)
- 面试题:AOF重写机制,redis面试必问!!!
- #DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)
- ICLR 2022 | pre training language model based on anti self attention mechanism
猜你喜欢
Cloud native technology container knowledge points
树的先序中序后序遍历
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
Advantages of link local address in IPv6
Aardio - construct a multi button component with customplus library +plus
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
(18) LCD1602 experiment
How to confirm the storage mode of the current system by program?
Rust knowledge mind map XMIND
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
随机推荐
cuda 探索
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
Cocoscreator+typescripts write an object pool by themselves
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
Gd32f4xx serial port receive interrupt and idle interrupt configuration
SQL server generates auto increment sequence number
Improving Multimodal Accuracy Through Modality Pre-training and Attention
How to achieve text animation effect
Aardio - Method of batch processing attributes and callback functions when encapsulating Libraries
MATLAB小技巧(27)灰色预测
Sword finger offer question brushing record 1
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
UDP programming
Const keyword
The ceiling of MySQL tutorial. Collect it and take your time
How to use flexible arrays?
Rust knowledge mind map XMIND
Puppeteer连接已有Chrome浏览器
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
「小程序容器技术」,是噱头还是新风口?