Added runner fixture
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kiss György · committed by Kiss György · parent b8e826c · Browse files · 1 file·+11 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+11 added−12 removed
- tests:+11 added−12 removed
Provenance
- Commit
1b764cf- Tree
b85ee36- Author
Kiss György <kissgyorgy@me.com>- Committer
Kiss György <kissgyorgy@me.com>- Parent
b8e826c
1 file changed+11 added−12 removed
modified:tests/test_cli.py+11 added-12 removed
23 unmodified lines24 find_best_app, locate_app, with_appcontext, prepare_exec_for_file, \25 find_default_import_path26 27 28+@pytest.fixture29+def runner():30+ return CliRunner()31+32+33 def test_cli_name(test_apps):34 """Make sure the CLI object's name is the app's name and not the app itself"""35 from cliapp.app import testapp36 assert testapp.cli.name == testapp.name75 unmodified lines112 assert app.name == "createapp"113 assert obj.load_app() == app114 115 111-def test_with_appcontext():116+def test_with_appcontext(runner):117 """Test of with_appcontext."""118 @click.command()119 @with_appcontext120 def testcmd():121 click.echo(current_app.name)122 123 obj = ScriptInfo(create_app=lambda info: Flask("testapp"))124 120- runner = CliRunner()125 result = runner.invoke(testcmd, obj=obj)126 assert result.exit_code == 0127 assert result.output == 'testapp\n'128 129 126-def test_appgroup():130+def test_appgroup(runner):131 """Test of with_appcontext."""132 @click.group(cls=AppGroup)133 def cli():134 pass11 unmodified lines146 click.echo(current_app.name)147 148 obj = ScriptInfo(create_app=lambda info: Flask("testappgroup"))149 146- runner = CliRunner()150 result = runner.invoke(cli, ['test'], obj=obj)151 assert result.exit_code == 0152 assert result.output == 'testappgroup\n'153 1 unmodified line155 assert result.exit_code == 0156 assert result.output == 'testappgroup\n'157 158 156-def test_flaskgroup():159+def test_flaskgroup(runner):160 """Test FlaskGroup."""161 def create_app(info):162 return Flask("flaskgroup")163 4 unmodified lines168 @cli.command()169 def test():170 click.echo(current_app.name)171 169- runner = CliRunner()172 result = runner.invoke(cli, ['test'])173 assert result.exit_code == 0174 assert result.output == 'flaskgroup\n'175 176 177 class TestRoutes:176- def test_no_route(self, monkeypatch):178+ def test_no_route(self, runner, monkeypatch):179 monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:noroute_app')178- runner = CliRunner()180 result = runner.invoke(cli, ['routes'], catch_exceptions=False)181 assert result.exit_code == 0182 assert result.output == """\183 Route Endpoint Methods 184 -----------------------------------------------------185 /static/<path:filename> static HEAD, OPTIONS, GET186 """187 187- def test_simple_route(self, monkeypatch):188+ def test_simple_route(self, runner, monkeypatch):189 monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:simpleroute_app')189- runner = CliRunner()190 result = runner.invoke(cli, ['routes'], catch_exceptions=False)191 assert result.exit_code == 0192 assert result.output == """\193 Route Endpoint Methods 1 unmodified line195 /simpleroute simple HEAD, OPTIONS, GET196 /static/<path:filename> static HEAD, OPTIONS, GET197 """198 199- def test_only_POST_route(self, monkeypatch):199+ def test_only_POST_route(self, runner, monkeypatch):200 monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:only_POST_route_app')201- runner = CliRunner()201 result = runner.invoke(cli, ['routes'], catch_exceptions=False)202 assert result.exit_code == 0203 assert result.output == """\204 Route Endpoint Methods 4 unmodified lines