How to run tests against a flask app returned from pytest fixture? #1510
-
For testing purpose, we set up a flask app in a pytest fixture. How do I access the flask app for testing through schemathesis library? Sample code: #conftest.py
@pytest.fixture
def app():
app = flask.Flask('our_app')
app_init(app, settings=settings)
return app #test_schema.py
schema = schemathesis.from_path("swagger.yaml")
@schema.parametrize()
def test_using_schemathesis(case, app):
case.call_and_validate(session=app) I have tried the above code and other variations but nothing seems to work. I couldn't find code samples from the documentation about how to access flask app defined in a fixture. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Here is an example, that you can transform to something like this: @pytest.fixture
def app():
app = flask.Flask('our_app')
app_init(app, settings=settings)
return app
schema = schemathesis.from_pytest_fixture("app")
@schema.parametrize()
def test_api(case, app):
response = case.call_wsgi(app=app)
case.validate_response(response) Here is some more info, let me know if that helps. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Stranger6667 for the response. I will try it and update. |
Beta Was this translation helpful? Give feedback.
Here is an example, that you can transform to something like this:
Here is some more info, let me know if that helps.