当前位置:网站首页>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
边栏推荐
- 【编译原理】做了一半的LR(0)分析器
- CUDA exploration
- #DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)
- How to use flexible arrays?
- Web APIs DOM time object
- The difference between enumeration and define macro
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- Use ECs to set up an agent
- Let's see through the network i/o model from beginning to end
- Signed and unsigned keywords
猜你喜欢
随机推荐
C three ways to realize socket data reception
Sizeof keyword
Bipartite graph determination
UDP编程
Enterprises do not want to replace the old system that has been used for ten years
Some suggestions for foreign lead2022 in the second half of the year
config:invalid signature 解决办法和问题排查详解
What are the specific steps and schedule of IELTS speaking?
监控界的最强王者,没有之一!
cuda 探索
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
Redis 持久化机制
第十九章 使用工作队列管理器(二)
「小程序容器技术」,是噱头还是新风口?
Void keyword
Cloud native technology container knowledge points
【无标题】
树的先序中序后序遍历
Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
项目复盘模板