Skip to content

Instantly share code, notes, and snippets.

@tribals
Last active October 19, 2017 13:54
Show Gist options
  • Save tribals/cdfb36a8fc814215d4410ba6eabb01fc to your computer and use it in GitHub Desktop.
Save tribals/cdfb36a8fc814215d4410ba6eabb01fc to your computer and use it in GitHub Desktop.
Flask app.config in different thread
import pytest
from spike import create_app
@pytest.fixture
def app():
return create_app()
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[dev-packages]
[packages]
flask = "*"
pytest = "*"
pytest-flask = "*"
[requires]
python_version = "3.5"
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()
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