examples/tutorial/tests/conftest.py
def app():
    """Create and configure a new app instance for each test."""
    # create a temporary file to isolate the database for each test
    db_fd, db_path = tempfile.mkstemp()
    # create the app with common test config
    app = create_app({"TESTING": True, "DATABASE": db_path})

    # create the database and load test data
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)

    yield app

    # close and remove the temporary database
    os.close(db_fd)
    os.unlink(db_path)
Create and configure a new app instance for each test.
Create and configure a new app instance for each test.
Create and configure a new app instance for each test .
def app():
    db_fd, db_path = tempfile.mkstemp()
    app = create_app({"TESTING": True, "DATABASE": db_path})
    with app.app_context():
        init_db()
        get_db().executescript(_data_sql)
    yield app
    os.close(db_fd)
    os.unlink(db_path)
def app ( ) : db_fd , db_path = tempfile . mkstemp ( ) app = create_app ( { "TESTING" : True , "DATABASE" : db_path } ) with app . app_context ( ) : init_db ( ) get_db ( ) . executescript ( _data_sql ) yield app os . close ( db_fd ) os . unlink ( db_path )
Create and configure a new app instance for each test.
Create and configure a new app instance for each test .
"""Create and configure a new app instance for each test.""" # create a temporary file to isolate the database for each test # create the app with common test config # create the database and load test data # close and remove the temporary database