We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest 提供了 fixture 的特性, 并且允许在测试用例的入口函数处声明使用该fixture作为参数, 这是一个高价值特性, 需要被支持, pytest-fixture
期望可以将 fixture 当做为变量传递给实体函数.
可以替代 httprunner 的 setup_hooks 和 teardown_hooks 功能.
conftest.py
@pytest.fixture(scope="session", autouse=True) def session_fixture(request): """setup and teardown each task""" total_testcases_num = request.node.testscollected testcases = [] for item in request.node.items: testcase = { "name": item.cls.config.name, "path": item.cls.config.path, "node_id": item.nodeid, } testcases.append(testcase) logger.debug(f"collected {total_testcases_num} testcases: {testcases}") yield testcases # 返回fixture logger.debug(f"teardown task fixture") # teardown task # TODO: upload task summary
request_with_fixtures.yml
config: name: "request with fixture: session fixture" base_url: "https://postman-echo.com" usefixtures: ["session_fixture"] teststeps: - name: get with params request: method: GET url: /get params: info: "ip" headers: User-Agent: HttpRunner/${get_httprunner_version()}/${get_session_fixture($session_fixture)}
request_with_fixtures_test.py
# NOTE: Generated By HttpRunner v3.1.6 # FROM: request_methods/request_with_fixtures.yml import debugtalk import pytest import allure from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase class TestCaseRequestWithFixtures(HttpRunner): @allure.title("request teststep: with error retry") def test_start(self, session_fixture): scope, fixtures = locals(), ["session_fixture"] values = map(lambda x: scope.get(x), fixtures) super().test_start(fixtures=dict(zip(fixtures, values))) config = Config("request teststep: with error retry").base_url( "https://postman-echo.com" ) teststeps = [ Step( RunRequest("get with params") .get("/get") .with_params(**{"info": "ip"}) .with_headers( **{ "User-Agent": "HttpRunner/${get_httprunner_version()}/${get_session_fixture($session_fixture)}" } ) ), ] if __name__ == "__main__": TestCaseRequestWithFixtures().test_start()
The text was updated successfully, but these errors were encountered:
feature: httprunner#1160 add support for pytest fixture as param
ce9d761
4088c24
d287b2f
debugtalk
No branches or pull requests
背景描述
pytest 提供了 fixture 的特性,
并且允许在测试用例的入口函数处声明使用该fixture作为参数,
这是一个高价值特性, 需要被支持, pytest-fixture
期望的功能特性
期望可以将 fixture 当做为变量传递给实体函数.
可以替代 httprunner 的 setup_hooks 和 teardown_hooks 功能.
示例描述(可选)
conftest.py
request_with_fixtures.yml
request_with_fixtures_test.py
The text was updated successfully, but these errors were encountered: