dict( TESTING=True, # Propagate exceptions LOGIN_DISABLED=False, # Enable @register_required MAIL_SUPPRESS_SEND=True, # Disable Flask-Mail send SERVER_NAME='localhost', # Enable url_for() without request context SQLALCHEMY_DATABASE_URI='sqlite:///:memory:', # In-memory SQLite DB WTF_CSRF_ENABLED=False, # Disable CSRF form validation )) # Setup an application context # (since the tests run outside of the webserver context) the_app.app_context().push() # Create and populate roles and users tables from app.commands.init_db import init_db # noqa init_db() @pytest.fixture(scope='session') def app(): """ Makes the 'app' parameter available to test functions. """ return the_app @pytest.fixture(scope='session') def db(): """ Makes the 'db' parameter available to test functions. """ return the_db @pytest.fixture(scope='function')
def teardown(): transaction.rollback() connection.close() session.remove() init_db()
the_app = create_app( dict( TESTING=True, # Propagate exceptions LOGIN_DISABLED=False, # Enable @register_required MAIL_SUPPRESS_SEND=True, # Disable Flask-Mail send SERVER_NAME="localhost", # Enable url_for() without request context SQLALCHEMY_DATABASE_URI="sqlite:///:memory:", # In-memory SQLite DB WTF_CSRF_ENABLED=False, # Disable CSRF form validation ) ) # Setup an application context (since the tests run outside of the webserver context) the_app.app_context().push() # Create and populate roles and users tables init_db(is_test_db=True) @pytest.fixture(scope="session") def app(): """ Makes the 'app' parameter available to test functions. """ return the_app @pytest.fixture(scope="session") def db(): """ Makes the 'db' parameter available to test functions. """ return the_db @pytest.fixture(scope="function")