jmcarp / jmcarp/flask-apispec

TypeError when running unittest on app with Blueprints

Open
#56 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
652
Forks
151
PR merge metrics
No merged PRs in 30d

Description

Given the following test app:

```python
# app.py
from flask import Blueprint, jsonify, Flask
from flask_apispec import FlaskApiSpec

docs = FlaskApiSpec()
blue = Blueprint('blue', __name__)

@blue.route('/', methods=['GET'])
def index():
return jsonify({'test': 123})

def create_app():
app = Flask(__name__)

docs.init_app(app)

app.register_blueprint(blue)
docs.register_existing_resources()

return app

app = create_app()

# test.py
import unittest

from flask import url_for

from app import create_app

class MyTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app()
self.app.config.update({'TESTING': True,
'SERVER_NAME': 'localhost'})
self.app_context = self.app.app_context()
self.app_context.push()
self.client = self.app.test_client()

def tearDown(self):
self.app_context.pop()

class ApiTestCase(MyTestCase):

def test_200(self):
res = self.client.get(url_for('blue.index'))
self.assertEqual(res.status_code, 200)

if __name__ == '__main__':
unittest.main()
```

running the tests in test.py will raise:
```
Traceback (most recent call last):
File "test.py", line 10, in setUp
self.app = create_app()
File "[..snip...]/app.py", line 16, in create_app
docs.init_app(app)
File "[..snip...]/venv/lib64/python3.6/site-packages/flask_apispec/extension.py", line 60, in init_app
deferred()
File "[..snip...]/venv/lib64/python3.6/site-packages/flask_apispec/extension.py", line 144, in _register
raise TypeError()
TypeError
```

extending the TypeError to output the `target` gives:
`TypeError: (>)`

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the app.py and test.py example using unittest. Start at flask_apispec/extension.py, especially init_app() and _register() around line 144, and inspect how the reported target is handled. Done means the test runs without the TypeError and test_200 still receives a 200 response.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.