Add test for routes command when no routes registered

This commit is contained in:
Grey Li 2018-05-31 11:43:51 +08:00
parent 0b4296ff17
commit 4025e27b57

View file

@ -393,6 +393,17 @@ class TestRoutes:
cli = FlaskGroup(create_app=create_app)
return partial(runner.invoke, cli)
@pytest.fixture
def invoke_no_routes(self, runner):
def create_app(info):
app = Flask(__name__, static_folder=None)
app.testing = True
return app
cli = FlaskGroup(create_app=create_app)
return partial(runner.invoke, cli)
def expect_order(self, order, output):
# skip the header and match the start of each row
for expect, line in zip(order, output.splitlines()[2:]):
@ -430,6 +441,11 @@ class TestRoutes:
output = invoke(['routes', '--all-methods']).output
assert 'GET, HEAD, OPTIONS, POST' in output
def test_no_routes(self, invoke_no_routes):
result = invoke_no_routes(['routes'])
assert result.exit_code == 0
assert 'No routes were registered.' in result.output
need_dotenv = pytest.mark.skipif(
dotenv is None, reason='dotenv is not installed'