From 35c32eccc10795d273634125be7280c529a1d175 Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Sat, 19 Apr 2014 15:57:03 -0400 Subject: [PATCH] Fix app fixture scope. Make function-scoped to make tests more isolated --- {{cookiecutter.app_name}}/tests/conftest.py | 2 +- {{cookiecutter.app_name}}/tests/test_webtests.py | 4 ++-- .../{{cookiecutter.app_name}}/settings.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/{{cookiecutter.app_name}}/tests/conftest.py b/{{cookiecutter.app_name}}/tests/conftest.py index 2d3240b..42774cc 100644 --- a/{{cookiecutter.app_name}}/tests/conftest.py +++ b/{{cookiecutter.app_name}}/tests/conftest.py @@ -10,7 +10,7 @@ from {{cookiecutter.app_name}}.app import create_app from {{cookiecutter.app_name}}.database import db as _db -@pytest.yield_fixture(scope='session') +@pytest.yield_fixture(scope='function') def app(): _app = create_app(TestConfig) ctx = _app.test_request_context() diff --git a/{{cookiecutter.app_name}}/tests/test_webtests.py b/{{cookiecutter.app_name}}/tests/test_webtests.py index 1c99da1..e0368c7 100644 --- a/{{cookiecutter.app_name}}/tests/test_webtests.py +++ b/{{cookiecutter.app_name}}/tests/test_webtests.py @@ -24,7 +24,7 @@ class TestLoggingIn: form['username'] = user.username form['password'] = 'myprecious' # Submits - res = form.submit() + res = form.submit().follow() assert res.status_code == 200 def test_sees_alert_on_log_out(self, user, testapp): @@ -34,7 +34,7 @@ class TestLoggingIn: form['username'] = user.username form['password'] = 'myprecious' # Submits - res = form.submit() + res = form.submit().follow() res = testapp.get(url_for('public.logout')).follow() # sees alert assert 'You are logged out.' in res diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/settings.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/settings.py index 50a3bc3d..03efe74 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/settings.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/settings.py @@ -3,10 +3,11 @@ import os class Config(object): - SECRET_KEY = 'shhhh' + SECRET_KEY = 'shhhh' # TODO: Change me APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory PROJECT_ROOT = os.path.abspath(os.path.join(APP_DIR, os.pardir)) BCRYPT_LOG_ROUNDS = 13 + ASSETS_DEBUG = False DEBUG_TB_ENABLED = False # Disable Debug toolbar DEBUG_TB_INTERCEPT_REDIRECTS = False CACHE_TYPE = 'simple' # Can be "memcached", "redis", etc. @@ -16,7 +17,7 @@ class ProdConfig(Config): """Production configuration.""" ENV = 'prod' DEBUG = False - SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' + SQLALCHEMY_DATABASE_URI = 'postgresql://localhost/example' # TODO: Change me DEBUG_TB_ENABLED = False # Disable Debug toolbar