import pytest import os from scripts.create_database import run from app import app from dotenv import load_dotenv from flask.testing import FlaskClient class TestBase: """ Base test class that ensures environment variables and test setup is complete before any other unit tests are run """ def setup_class(self): """ Setup class level resources or configurations Setup test environment variables """ load_dotenv() # Capture environment variables at start of testing so we can # Monitor current setting during tests self.old_env = os.environ.get("ENVIRON") os.environ["ENVIRON"] = "test" run() def teardown_class(self): """ Teardown class level resources or configurations """ pass @pytest.fixture(scope="class") def test_client(self) -> FlaskClient: """ Enables tests to create requests to the web app """ os.environ['CONFIG_TYPE'] = 'config.TestingConfig' with app.test_client() as testing_client: with app.app_context(): yield testing_client