When I run pytest
on the following code:
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
I get this warning: "... .venv/lib/python3.11/site-packages/pytest_bdd/steps.py:211: PytestDeprecationWarning: A private pytest class or function was used. fd = FixtureDef( "
When I remove the target_fixture
parameter from the @when
decorator, the warning goes away. I understand I can capture the warning but I don't want to capture deprecation warnings, I'd rather know what's causing this and how to fix it.
This is my requirements.txt file:
pytest==8.0.0
boto3==1.34.39
pytest-bdd==7.0.1
devtools==0.12.2
requests==2.31.0
I am facing the same problem. I suspect the problem is between pytest and pytest-bdd, and not yours or my code. For now I run tests with:
which you can configure by creating (or modifying) pytest.ini:
ETA: I know your preference is not to suppress warnings (me too!) but it took me a while to learn how to do this, so for those facing the same issue this may be helpful.