Last active
October 19, 2017 13:54
-
-
Save tribals/cdfb36a8fc814215d4410ba6eabb01fc to your computer and use it in GitHub Desktop.
Flask app.config in different thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from spike import create_app | |
@pytest.fixture | |
def app(): | |
return create_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[source]] | |
url = "https://pypi.python.org/simple" | |
verify_ssl = true | |
name = "pypi" | |
[dev-packages] | |
[packages] | |
flask = "*" | |
pytest = "*" | |
pytest-flask = "*" | |
[requires] | |
python_version = "3.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread | |
from flask import Flask | |
def trying_to_access_app_config(): | |
assert app.config['my_option'] | |
def create_app(): | |
app = Flask(__name__) | |
@app.route('/') | |
def root(): | |
Thread(target=trying_to_access_app_config).start() | |
return 'Kicked up!' | |
return app | |
app = create_app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
def test_app_config_in_different_thread(client, config): | |
config['my_option'] = 'spam' | |
resp = client.get('/') | |
assert resp.data == b'Kicked up!' | |
@pytest.mark.options(my_option=42) | |
def test_app_config_again(client): | |
resp = client.get('/') | |
assert resp.data == b'Kicked up!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment