さらに
、図に示すように、テストケースファイルtest_1.pyを実行すると、pytestフレームワークの実行シーケンスは
次のようになります。(1)最初にスーツのconftestファイルを特定し、それを実行します
(2)次にconftestファイルを特定しますtest_1で実行し、実行します
(3)test_1.pyファイルを実行します
conftest.pyの概要:
(1)テストケースの前提条件を処理するために一般的に使用されます。また、テストケースのファイルtest_1.pyから呼び出すことができるフィクスチャでいくつかの関数をマークします。
(2)ファイル名はpytestフレームワークによってハードコーディングされています。スーツのconfファイルのtest_1と2の内容が実行され、test_1のconfファイルはtest_1が実行されたときにのみ実行されます。
(3)このファイルをtest_1.pyファイルにインポートする必要はありません。pytestが自動的に実行します。
(4)ファイルの内容
スーツのconftest.pyファイル
# coding=utf-8
import pytest
from selenium import webdriver
@pytest.fixture(autouse=True)
def project_session_start():
print('\n启动浏览器')
yield
print('\n退出浏览器')
test_1のconfファイル:
# coding=utf-8
import pytest
from selenium import webdriver
import logging
logger = logging.getLogger()
@pytest.fixture(autouse=True)
def start_module():
print('---进入要执行模块的的界面---')
Test_1、pyコード、および実行後の状況:
# coding=utf-8
import pytest
@pytest.fixture()
def test_case_3():
print('---3号用例完成---')
@pytest.fixture()
def test_case_4():
print('---4号用例完成---')
@pytest.fixture()
def test_case_5():
print('---5号用例完成---')
@pytest.fixture()
def test_case_6():
print('---6号用例完成---')
@pytest.fixture()
def test_case_7():
print('---7号用例完成---')
# (1)这里按照【从下到上的顺序】,执行优先级是3、4、5
@pytest.mark.usefixtures('test_case_5')
@pytest.mark.usefixtures('test_case_4')
@pytest.mark.usefixtures('test_case_3')
class Testlogin001:
def test_case_1(self):
print('---1号用例完成---')
# (2)这里按照调用了前面的函数test_case_6,局部的调用,执行优先级是最高的。
@pytest.mark.usefixtures('test_case_7')
@pytest.mark.usefixtures('test_case_6')
def test_case_2(self):
print('---2号用例完成---')
if __name__ == "__main__":
pytest.main(['-vs', 'test_1.py'])
C:\Python39\python.exe D:/se_frame/Cases/MapAaaCases/test_1.py
collecting ... collected 2 items
test_1.py::Testlogin001::test_case_1
启动浏览器
---进入要执行模块的的界面---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---1号用例完成---
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_2
启动浏览器
---进入要执行模块的的界面---
---6号用例完成---
---7号用例完成---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---2号用例完成---
PASSED
退出浏览器