当前位置:网站首页>Pytest interface automated testing framework | confitest Py and @pytest Fixture() combination
Pytest interface automated testing framework | confitest Py and @pytest Fixture() combination
2022-07-18 23:41:00 【COCOgsta】
Video source :B standing 《 Risking your life to upload !pytest Interface automation test framework ( From basic theory to project practice and secondary development ) Teaching video 【 software test 】》
Organize the teacher's course content and test notes while studying , And share it with you , Infringement is deleted , Thank you for your support !
Use cases 1 You need to log in first , Use cases 2 You don't need to log in , Use cases 3 You need to log in first , The preconditions are different in different use cases
conftest.py Configuration requires some attention to the following points :
- conftest.py The configuration script name is fixed , You can't change the name , It is a configuration file stored separately .
- In principle, ,conftest.py The same as the running use case package Next , And there are init.py file , Can be in different py Use the same in the file fixture function
- Unwanted import Import conftest.py,pytest Use cases are automatically found
- Generally speaking , There is one under different modules conftest.py file . There is a global conftest.py
conftest.py
import pytest
# Scope
@pytest.fixture(scope='class', autouse=True)
def login():
print(' Login system ')
yield
print(' Exit the system ')py1_test.py
import pytest
# conftest.py
# 1.conftest Under the same directory of use cases
# 2.conftest The name cannot be changed
# 3. No need to import , Auto find fixture
class TestCase1:
def test_03(self):
print(' Test case three ')
def test_04(self):
print(' Test case four ')Running results :
/Users/guoliang/SynologyDrive/SourceCode/pytest3/venv/bin/python /Users/guoliang/SynologyDrive/SourceCode/pytest3/all.py
============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-7.1.2, pluggy-1.0.0 -- /Users/guoliang/SynologyDrive/SourceCode/pytest3/venv/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.7.6', 'Platform': 'Darwin-17.7.0-x86_64-i386-64bit', 'Packages': {'pytest': '7.1.2', 'py': '1.11.0', 'pluggy': '1.0.0'}, 'Plugins': {'xdist': '2.5.0', 'forked': '1.4.0', 'metadata': '2.0.1', 'allure-pytest': '2.9.45', 'rerunfailures': '10.2', 'html': '3.1.1', 'ordering': '0.6'}}
rootdir: /Users/guoliang/SynologyDrive/SourceCode/pytest3, configfile: pytest.ini, testpaths: ./testcase
plugins: xdist-2.5.0, forked-1.4.0, metadata-2.0.1, allure-pytest-2.9.45, rerunfailures-10.2, html-3.1.1, ordering-0.6
collecting ... collected 2 items
testcase/py1_test.py::TestCase1::test_03 Login system
Test case three
PASSED
testcase/py1_test.py::TestCase1::test_04 Test case four
PASSED Exit the system
============================== 2 passed in 0.02s ===============================
Process finished with exit code 0
The overall situation is conftest.py, There are also conftest.py
/conftest.py
import pytest
# Scope
@pytest.fixture(scope='session', autouse=True)
def login():
print(' Login system ')
yield
print(' Exit the system ')
# Execution order
# Login system - Commodity use case 3 Commodity use case 4 - Exit the system
# Login system - User case 3 User case 4 - Exit the system /testcase/pro/conftest.py
import pytest
@pytest.fixture(scope='class', autouse=True)
def login1():
print(' Enter commodity management ')
yield
print(' Exit commodity management ')/testcase/user/conftest.py
import pytest
@pytest.fixture(scope='class', autouse=True)
def login2():
print(' Enter user management ')
yield
print(' Exit user management ')/testcase/pro/pro_test.py
class TestCase2:
def test_3(self):
print(' Commodity use case 3 ')
def test_4(self):
print(' Commodity use case 4 ')/testcase/user/user_test.py
# conftest.py
# 1.conftest Under the same directory of use cases ,
# Log on first Enter user management -- User case Exit user management Log out
# Log on first Enter commodity management -- Commodity use case Exit commodity management Log out
# Log on first Enter user management -- User case Exit user management Enter commodity management -- Commodity use case Exit commodity management Log out
# Scope
# 2.conftest The name cannot be changed
# 3. No need to import , Auto find fixture
class TestCase1:
def test_03(self):
print(' User case 3 ')
def test_04(self):
print(' User case 4 ')Running results :
/Users/guoliang/SynologyDrive/SourceCode/pytest3/venv/bin/python /Users/guoliang/SynologyDrive/SourceCode/pytest3/all.py
============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-7.1.2, pluggy-1.0.0 -- /Users/guoliang/SynologyDrive/SourceCode/pytest3/venv/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.7.6', 'Platform': 'Darwin-17.7.0-x86_64-i386-64bit', 'Packages': {'pytest': '7.1.2', 'py': '1.11.0', 'pluggy': '1.0.0'}, 'Plugins': {'xdist': '2.5.0', 'forked': '1.4.0', 'metadata': '2.0.1', 'allure-pytest': '2.9.45', 'rerunfailures': '10.2', 'html': '3.1.1', 'ordering': '0.6'}}
rootdir: /Users/guoliang/SynologyDrive/SourceCode/pytest3, configfile: pytest.ini, testpaths: ./testcase
plugins: xdist-2.5.0, forked-1.4.0, metadata-2.0.1, allure-pytest-2.9.45, rerunfailures-10.2, html-3.1.1, ordering-0.6
collecting ... collected 4 items
testcase/pro/pro_test.py::TestCase2::test_3 Login system
Enter commodity management
Commodity use case 3
PASSED
testcase/pro/pro_test.py::TestCase2::test_4 Commodity use case 4
PASSED Exit commodity management
testcase/user/user_test.py::TestCase1::test_03 Enter user management
User case 3
PASSED
testcase/user/user_test.py::TestCase1::test_04 User case 4
PASSED Exit user management
Exit the system
============================== 4 passed in 0.05s ===============================
Process finished with exit code 0
边栏推荐
- 【Leetcode】225. Implement stack with queue
- Hibench generates benchmark data sets [wordcount as an example]
- Mysql事务隔离机制
- Canadian deployer Canadian adapter image construction, deployment
- 微信小程序_16,组件的生命周期
- Basic knowledge of common amplifiers (I)
- GDB debugging skills: positioning program stuck problem
- Design of DHT11 temperature and humidity sensor based on stm32
- Preliminary test of ZVS circuit
- 从0开始安装苹果cms及其资源采集和页面部分代码
猜你喜欢

Reproduce pytorch version from zero (2)

Wechat applet_ 16. Component life cycle

单行文本 超出部分省略号,多行文本超出部分省略号,指定多行

11、摸清JVM对象分布

Pay attention to using yyyy-mm-dd in the code!

ngrx store 状态管理
![[technology fragment] rename suffix of duplicate files based on exponential diffusion binary search](/img/1c/19fe2d9df5e075b903058aa0b9b521.png)
[technology fragment] rename suffix of duplicate files based on exponential diffusion binary search

p5js咖啡杯冒热气js特效

yarn /nmp全局安装后,命令不生效

canal-deployer canal-adapter镜像构建,部署
随机推荐
Canadian deployer Canadian adapter image construction, deployment
Sword finger offer II 119 Longest continuous sequence
nodeJS中对Promise模块介绍
pytest接口自动化测试框架 | @pytest.fixture()装饰器
STM32F1与STM32CubeIDE编程实例-W25Q-SPI-Flash与FatFs移植
pytest接口自动化测试框架 | 接口关联
Mysql的锁机制
Summary of binary search questions
p5js咖啡杯冒热气js特效
Compose uses coil to load network pictures
动态内存管理(C语言)下--常见错误及大厂笔试题
leetcode-两数之和
广州铁骑霸气“公主抱”,安全感拉满!
嘘!摸鱼神器,别让老板知道!| 语音实时转文本,时序快速出预测,YOLOv6在就能用,一行命令整理CSV | ShowMeAI资讯日报
回到顶部,滚动条慢慢回到顶部
6、JVM分代模型--老年代 的垃圾回收
Recent software test interview questions encountered by group Friends
利用备份恢复数据库,但是没有控制文件文件如何解决
Summary of this week 2
星巴克不使用两阶段提交