-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI commands require a Flask test request context #3760
Labels
Comments
amercader
added a commit
that referenced
this issue
Aug 23, 2017
This is an attempt to try to avoid having to explicitly generate a Flask request context on all tests that involve url_for. There are two scenarios when url_for is called outside the context of a web request: tests and CLI. The idea is to provide a fallback test request context on url_for if there isn't one available. On tests, we have the added complexity that tests can modify the configuration and plugins loaded so we can't reuse the same. This is an ugly patch, as it uses to global variables. For CLI commands there's a test request context created on `load_config`, which all commands should run on startup. For tests, the only safe place to create it is at the lowest level, on `make_app`, as soon as the environment is loaded and there is a Flask app available. Of course this only works if the tests create a test web app, but that is the most common scenario (eg `FunctionalTestBase` or any test that creates its own app). Other tests can create their own test request context if needeed.
amercader
added a commit
that referenced
this issue
Aug 23, 2017
wardi
added a commit
that referenced
this issue
Aug 30, 2017
[#3760] Create a test request context automatically if missing in url_for
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On latest master, running a paster command that involves URL generation (like
paster search-index rebuild
) will throw the infamousRuntimeError: Attempted to generate a URL without the application context being pushed
exception:Why this is happening is explained here. As per Flask documentation, we need to create a test request context.
The text was updated successfully, but these errors were encountered: