July 2019
Beginner to intermediate
302 pages
9h 38m
English
Let's write our first test case:
import os from my_app import app, db import unittest import tempfile
The preceding code describes the imports needed for this test suite. We will use unittest for writing our tests. A tempfile instance is needed to create SQLite databases on the fly.
class CatalogTestCase(unittest.TestCase):
def setUp(self):
self.test_db_file = tempfile.mkstemp()[1]
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.test_db_file
app.config['TESTING'] = True
self.app = app.test_client()
db.create_all()
The preceding method is run before each test is run and creates ...