当前位置:网站首页>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
边栏推荐
- Typescript get function parameter type
- Word2vec (skip gram and cbow) - pytorch
- CUDA exploration
- 2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
- [leetcode] 19. Delete the penultimate node of the linked list
- Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
- npm无法安装sharp
- QT signal and slot
- 服务器的系统怎么选者
- Signed and unsigned keywords
猜你喜欢
Rust knowledge mind map XMIND
儿童睡衣(澳大利亚)AS/NZS 1249:2014办理流程
#DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
How to confirm the storage mode of the current system by program?
Cloud native technology container knowledge points
Bipartite graph determination
Let's see through the network i/o model from beginning to end
cuda 探索
Aardio - Method of batch processing attributes and callback functions when encapsulating Libraries
随机推荐
NPM cannot install sharp
Aardio - Method of batch processing attributes and callback functions when encapsulating Libraries
On the problems of born charge and non analytical correction in phonon and heat transport calculations
On file uploading of network security
雅思口语的具体步骤和时间安排是什么样的?
Gd32f4xx serial port receive interrupt and idle interrupt configuration
Jafka来源分析——Processor
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
Use ECs to set up an agent
QT signal and slot
(18) LCD1602 experiment
config:invalid signature 解决办法和问题排查详解
Some suggestions for foreign lead2022 in the second half of the year
MySQL教程的天花板,收藏好,慢慢看
让我们,从头到尾,通透网络I/O模型
poj 1094 Sorting It All Out (拓扑排序)
Extern keyword
SQL server generates auto increment sequence number
Chapter 19 using work queue manager (2)
存币生息理财dapp系统开发案例演示