PytestBDD target_fixture - PytestDeprecationWarning

问题描述 投票:0回答:1

当我在以下代码上运行

pytest
时:

import requests

from pytest_bdd import scenario, given, when, then

@scenario('../features/user.feature', 'Create a new user')
def test_create_user():
    pass

@given('a valid user payload')
def valid_user_payload():
    return {
        "username": "TEST"
    }

@when('a client calls POST /users', target_fixture='response')
def create_user():
    api_base_url = "https://localhost:8080"
    response = requests.post(f"{api_base_url}/users", json="user_payload")
    return response

我收到此警告:“... .venv/lib/python3.11/site-packages/pytest_bdd/steps.py:211: PytestDeprecationWarning: 使用了私有 pytest 类或函数。 fd = FixtureDef( ”

当我从

target_fixture
装饰器中删除
@when
参数时,警告就会消失。我知道我可以捕获警告,但我不想捕获弃用警告,我宁愿知道导致此问题的原因以及如何修复它。

这是我的requirements.txt文件:

pytest==8.0.0
boto3==1.34.39
pytest-bdd==7.0.1
devtools==0.12.2
requests==2.31.0
python pytest pytest-bdd
1个回答
0
投票

我也面临着同样的问题。我怀疑问题出在 pytest 和 pytest-bdd 之间,而不是你的或我的代码。现在我运行测试:

pytest -W ignore::pytest.PytestDeprecationWarning

您可以通过创建(或修改)pytest.ini进行配置:

[pytest]
filterwarnings =
    ignore::pytest.PytestDeprecationWarning

ETA:我知道你的偏好不是抑制警告(我也是!),但我花了一段时间才学会如何做到这一点,所以对于那些面临同样问题的人来说这可能会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.