pytest-dev / pytest-flask

A set of pytest fixtures to test Flask applications

Home Page:http://pytest-flask.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configurable scope for normal app and client fixtures

languitar opened this issue · comments

Is your feature request related to a problem? Please describe.

Even when not using the live server feature, starting and stopping the flask app can add a noticeable delay to the test execution. Therefore, it would be nice of the in-process fixtures can optionally also be used with session scope.

Describe the solution you'd like

Similar to what has been implemented #112 , the fixture for the in-process app should also be configurable to different scopes.

Describe alternatives you've considered

I would have to reimplement the fixture without this feature.

Thanks for taking the time to open the issue @languitar.

I might be misinterpreting what you meant, but since the app fixture is defined by the user (in your conftest.py file), its scope can be set as follows:

@pytest.fixture(scope="session")
def app():
    app = Flask(__name__)
    # ...
    @app.route("/ping")
    def ping():
        return jsonify(ping="pong")

    return app

Good point. I thought something inside pytest-flask was preventing me from doing this. But now that I tried it again, everything works as expected.

Sorry for the noise and thanks for the help.

Glad to help 👍🏻