Testing¶
Included pytest fixtures¶
app¶
maybe_inject_extensions_and_services¶
-
flask_unchained.pytest.
maybe_inject_extensions_and_services
(app, request)[source]¶ Automatically used test fixture. Allows for using services and extensions as if they were test fixtures:
def test_something(db, mail, security_service, user_manager): # assert important stuff
NOTE: This only works on tests themselves; it will not work on test fixtures
cli_runner¶
-
flask_unchained.pytest.
cli_runner
(app)[source]¶ Yields an instance of
FlaskCliRunner
. Example usage:from your_package.commands import some_command def test_some_command(cli_runner): result = cli_runner.invoke(some_command) assert result.exit_code == 0 assert result.output.strip() == 'output of some_command'
client¶
-
flask_unchained.pytest.
client
(app)[source]¶ Yields an instance of
HtmlTestClient
. Example usage:def test_some_view(client): r = client.get('some.endpoint') # r is an instance of :class:`HtmlTestResponse` assert r.status_code == 200 assert 'The Page Title' in r.html
api_client¶
-
flask_unchained.pytest.
api_client
(app)[source]¶ Yields an instance of
ApiTestClient
. Example usage:def test_some_view(api_client): r = api_client.get('some.endpoint.returning.json') # r is an instance of :class:`ApiTestResponse` assert r.status_code == 200 assert 'some_key' in r.json
templates¶
-
flask_unchained.pytest.
templates
(app)[source]¶ Fixture to record which templates (if any) got rendered during a request. Example Usage:
def test_some_view(client, templates): r = client.get('some.endpoint') assert r.status_code == 200 assert templates[0].template.name == 'some/template.html' assert templates[0].context.get('some_ctx_var') == 'expected value'