It seems like not matter what happens, the flask request and instance of Flask (and instance of a Blueprint if using that) always require some kind of global finagling. And when I remove all the globals (except for request) the instance of Flask that typically one names "app" will work with app.run() but then all the routes respond 404.
EDIT: Here's the boilerplate example with global vars:
from flask import Flask
app = Flask("MyAppName")
@app.route("/hello")
def hello_world():
return "hello world"
if __name__ == "__main__":
app.run()
EDIT 2: Here's the failing example written as a test. Instead of passing around the global variable, we can instantiate a new one, but then the decorators fail. So I don't know if it can be done.
So the two modules, one called views.py:
from flask import Flask
def get_route_index():
return "/foobuz"
def get_app():
return Flask(__name__)
app = get_app()
@app.route(get_route_index())
def index():
return "Stub foobuz app."
And the second module test_views.py:
import unittest
from flask_testing import TestCase
from werkzeug.test import Client
from views import get_app, get_route_index, # app
class TestFoobuzPackage(TestCase):
def setUp(self):
pass
def create_app(self):
app = get_app()
app.config["TESTING"] = True
self.client = app.test_client()
return app
def tearDown(self):
pass
def test_index(self):
response = Client.open(
self.client,
path=get_route_index(),
)
self.assert_200(response)