当前位置:网站首页>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
边栏推荐
- BasicVSR_PlusPlus-master测试视频、图片
- Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
- Pit encountered by handwritten ABA
- The ceiling of MySQL tutorial. Collect it and take your time
- Clip +json parsing converts the sound in the video into text
- Comparison between variable and "zero value"
- Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
- How to use flexible arrays?
- On file uploading of network security
- Sword finger offer question brushing record 1
猜你喜欢

剑指offer刷题记录1

Aardio - construct a multi button component with customplus library +plus

案例推荐丨安擎携手伙伴,保障“智慧法院”更加高效

Custom swap function

Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)

DR-Net: dual-rotation network with feature map enhancement for medical image segmentation

Enterprises do not want to replace the old system that has been used for ten years

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

How to choose indoor LED display? These five considerations must be taken into account

动作捕捉用于蛇运动分析及蛇形机器人开发
随机推荐
rust知识思维导图xmind
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
UVa 11732 – strcmp() Anyone?
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
Puppeter connects to the existing Chrome browser
Matlab tips (27) grey prediction
Introduction to network basics
云原生技术--- 容器知识点
Typescript get function parameter type
Puppeteer连接已有Chrome浏览器
Custom swap function
DockerMySQL无法被宿主机访问的问题解决
2014阿里巴巴web前实习生项目分析(1)
Advantages of link local address in IPv6
企業不想換掉用了十年的老系統
Inno setup packaging and signing Guide
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
Extern keyword
BasicVSR_ Plusplus master test videos and pictures