Skip to content

Commit 2bdff9c

Browse files
jwg4Jack Grahl
authored and
Jack Grahl
committed
Raise an error with a useful message if the app is not setup.
1 parent b07dfc8 commit 2bdff9c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

flask_selfdoc/autodoc.py

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ def html(self, groups='all', template=None, **context):
176176
By specifying the group or groups arguments, only routes belonging to
177177
those groups will be returned.
178178
"""
179+
if not self.app:
180+
raise RuntimeError("Autodoc was not initialized with the Flask app.")
179181
context['autodoc'] = context['autodoc'] if 'autodoc' in context \
180182
else self.generate(groups=groups)
181183
context['defaults'] = context['defaults'] if 'defaults' in context \

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def readme():
4040
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
4141
'Topic :: Software Development :: Libraries :: Python Modules'
4242
],
43-
test_suite='tests.test_autodoc',
43+
test_suite='tests',
4444
)

tests/test_error_handling.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import unittest
2+
3+
from flask import Flask
4+
from flask_autodoc import Autodoc
5+
6+
7+
class TestErrorHandling(unittest.TestCase):
8+
def test_app_not_initialized(self):
9+
app = Flask(__name__)
10+
app.debug = True
11+
autodoc = Autodoc()
12+
with app.app_context():
13+
self.assertRaises(RuntimeError, lambda: autodoc.html())

0 commit comments

Comments
 (0)