From 1b764cff93696a75c6248b6f956426cbefa097bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20Gy=C3=B6rgy?= Date: Sat, 25 Jun 2016 13:24:43 +0200 Subject: [PATCH] Added runner fixture --- tests/test_cli.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7df00167..db82ae8e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,6 +25,11 @@ from flask.cli import cli, AppGroup, FlaskGroup, NoAppException, ScriptInfo, \ find_default_import_path +@pytest.fixture +def runner(): + return CliRunner() + + def test_cli_name(test_apps): """Make sure the CLI object's name is the app's name and not the app itself""" from cliapp.app import testapp @@ -108,7 +113,7 @@ def test_scriptinfo(test_apps): assert obj.load_app() == app -def test_with_appcontext(): +def test_with_appcontext(runner): """Test of with_appcontext.""" @click.command() @with_appcontext @@ -117,13 +122,12 @@ def test_with_appcontext(): obj = ScriptInfo(create_app=lambda info: Flask("testapp")) - runner = CliRunner() result = runner.invoke(testcmd, obj=obj) assert result.exit_code == 0 assert result.output == 'testapp\n' -def test_appgroup(): +def test_appgroup(runner): """Test of with_appcontext.""" @click.group(cls=AppGroup) def cli(): @@ -143,7 +147,6 @@ def test_appgroup(): obj = ScriptInfo(create_app=lambda info: Flask("testappgroup")) - runner = CliRunner() result = runner.invoke(cli, ['test'], obj=obj) assert result.exit_code == 0 assert result.output == 'testappgroup\n' @@ -153,7 +156,7 @@ def test_appgroup(): assert result.output == 'testappgroup\n' -def test_flaskgroup(): +def test_flaskgroup(runner): """Test FlaskGroup.""" def create_app(info): return Flask("flaskgroup") @@ -166,16 +169,14 @@ def test_flaskgroup(): def test(): click.echo(current_app.name) - runner = CliRunner() result = runner.invoke(cli, ['test']) assert result.exit_code == 0 assert result.output == 'flaskgroup\n' class TestRoutes: - def test_no_route(self, monkeypatch): + def test_no_route(self, runner, monkeypatch): monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:noroute_app') - runner = CliRunner() result = runner.invoke(cli, ['routes'], catch_exceptions=False) assert result.exit_code == 0 assert result.output == """\ @@ -184,9 +185,8 @@ Route Endpoint Methods /static/ static HEAD, OPTIONS, GET """ - def test_simple_route(self, monkeypatch): + def test_simple_route(self, runner, monkeypatch): monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:simpleroute_app') - runner = CliRunner() result = runner.invoke(cli, ['routes'], catch_exceptions=False) assert result.exit_code == 0 assert result.output == """\ @@ -196,9 +196,8 @@ Route Endpoint Methods /static/ static HEAD, OPTIONS, GET """ - def test_only_POST_route(self, monkeypatch): + def test_only_POST_route(self, runner, monkeypatch): monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:only_POST_route_app') - runner = CliRunner() result = runner.invoke(cli, ['routes'], catch_exceptions=False) assert result.exit_code == 0 assert result.output == """\