import bookmarks
import unittest


class FlaskrTestCase(unittest.TestCase):
    def setUp(self):
        bookmarks.app.config['DATABASE_NAME'] = bookmarks.app.config['TEST_DATABASE_NAME']
        bookmarks.app.testing = True
        self.app = bookmarks.app.test_client()
        with bookmarks.app.app_context():
            bookmarks.database.init_db()

    # def tearDown(self):
    #     os.close(self.db_fd)
    #     os.unlink(bookmarks.app.config['DATABASE'])

    def test_empty_db(self):
        rv = self.app.get('/')
        assert b'There aren\'t any bookmarks yet.' in rv.data

if __name__ == '__main__':
    unittest.main()

import bookmarks
import unittest


class FlaskrTestCase(unittest.TestCase):
    def setUp(self):
        self.app = bookmarks.app.test_client()
        with bookmarks.app.app_context():
            bookmarks.database.init_db()

    def tearDown(self):
        with bookmarks.app.app_context():
            bookmarks.database.db_session.remove()
            bookmarks.database.Base.metadata.drop_all(
                bind=bookmarks.database.engine)

    def test_empty_db(self):
        rv = self.app.get('/')
        assert b'There aren\'t any bookmarks yet.' in rv.data

if __name__ == '__main__':
    unittest.main()

Adjust test file to match new env config options
Adjust test file to match new env config options

  import bookmarks
  import unittest
  
  
  class FlaskrTestCase(unittest.TestCase):
      def setUp(self):
-         bookmarks.app.config['DATABASE_NAME'] = bookmarks.app.config['TEST_DATABASE_NAME']
-         bookmarks.app.testing = True
          self.app = bookmarks.app.test_client()
          with bookmarks.app.app_context():
              bookmarks.database.init_db()
  
-     # def tearDown(self):
+     def tearDown(self):
-     #     os.close(self.db_fd)
-     #     os.unlink(bookmarks.app.config['DATABASE'])
+         with bookmarks.app.app_context():
+             bookmarks.database.db_session.remove()
+             bookmarks.database.Base.metadata.drop_all(
+                 bind=bookmarks.database.engine)
  
      def test_empty_db(self):
          rv = self.app.get('/')
          assert b'There aren\'t any bookmarks yet.' in rv.data
  
  if __name__ == '__main__':
      unittest.main()
  
Adjust test file to match new env config options
## Code Before:
import bookmarks
import unittest


class FlaskrTestCase(unittest.TestCase):
    def setUp(self):
        bookmarks.app.config['DATABASE_NAME'] = bookmarks.app.config['TEST_DATABASE_NAME']
        bookmarks.app.testing = True
        self.app = bookmarks.app.test_client()
        with bookmarks.app.app_context():
            bookmarks.database.init_db()

    # def tearDown(self):
    #     os.close(self.db_fd)
    #     os.unlink(bookmarks.app.config['DATABASE'])

    def test_empty_db(self):
        rv = self.app.get('/')
        assert b'There aren\'t any bookmarks yet.' in rv.data

if __name__ == '__main__':
    unittest.main()

## Instruction:
Adjust test file to match new env config options
## Code After:
import bookmarks
import unittest


class FlaskrTestCase(unittest.TestCase):
    def setUp(self):
        self.app = bookmarks.app.test_client()
        with bookmarks.app.app_context():
            bookmarks.database.init_db()

    def tearDown(self):
        with bookmarks.app.app_context():
            bookmarks.database.db_session.remove()
            bookmarks.database.Base.metadata.drop_all(
                bind=bookmarks.database.engine)

    def test_empty_db(self):
        rv = self.app.get('/')
        assert b'There aren\'t any bookmarks yet.' in rv.data

if __name__ == '__main__':
    unittest.main()
