from contextlib import closing
import pytest

from journal import app
from journal import connect_db
from journal import get_database_connection
from journal import init_db

TEST_DSN = 'dbname=test_learning_journal'


def clear_db():
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()


@pytest.fixture(scope='session')
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True

from contextlib import closing
import pytest

from journal import app
from journal import connect_db
from journal import get_database_connection
from journal import init_db

TEST_DSN = 'dbname=test_learning_journal'


def clear_db():
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()


@pytest.fixture(scope='session')
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True


@pytest.fixture(scope='session')
def db(test_app, request):
    """initialize the entries table and drop it when finished"""
    init_db()

    def cleanup():
        clear_db()

    request.addfinalizer(cleanup)
Add db() to initialize a table and drop when finished
Add db() to initialize a table and drop when finished

  from contextlib import closing
  import pytest
  
  from journal import app
  from journal import connect_db
  from journal import get_database_connection
  from journal import init_db
  
  TEST_DSN = 'dbname=test_learning_journal'
  
  
  def clear_db():
      with closing(connect_db()) as db:
          db.cursor().execute("DROP TABLE entries")
          db.commit()
  
  
  @pytest.fixture(scope='session')
  def test_app():
      """configure our app for use in testing"""
      app.config['DATABASE'] = TEST_DSN
      app.config['TESTING'] = True
  
+ 
+ @pytest.fixture(scope='session')
+ def db(test_app, request):
+     """initialize the entries table and drop it when finished"""
+     init_db()
+ 
+     def cleanup():
+         clear_db()
+ 
+     request.addfinalizer(cleanup)
Add db() to initialize a table and drop when finished
## Code Before:
from contextlib import closing
import pytest

from journal import app
from journal import connect_db
from journal import get_database_connection
from journal import init_db

TEST_DSN = 'dbname=test_learning_journal'


def clear_db():
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()


@pytest.fixture(scope='session')
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True

## Instruction:
Add db() to initialize a table and drop when finished
## Code After:
from contextlib import closing
import pytest

from journal import app
from journal import connect_db
from journal import get_database_connection
from journal import init_db

TEST_DSN = 'dbname=test_learning_journal'


def clear_db():
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()


@pytest.fixture(scope='session')
def test_app():
    """configure our app for use in testing"""
    app.config['DATABASE'] = TEST_DSN
    app.config['TESTING'] = True


@pytest.fixture(scope='session')
def db(test_app, request):
    """initialize the entries table and drop it when finished"""
    init_db()

    def cleanup():
        clear_db()

    request.addfinalizer(cleanup)