Flask/tests/conftest.py
Simon Diesenreiter 5efd61d236
Some checks failed
CI / linter (ubuntu-latest, 3.9) (push) Failing after 1m29s
Rename the project from template / rename-project (push) Has been skipped
CI / tests_linux (ubuntu-latest, 3.9) (push) Has been skipped
initial commit
2024-11-10 07:27:36 -08:00

34 lines
844 B
Python

import sys
import pytest
from project_name import create_app
from project_name.ext.commands import populate_db
from project_name.ext.database import db
@pytest.fixture(scope="session")
def app():
app = create_app(FORCE_ENV_FOR_DYNACONF="testing")
with app.app_context():
db.create_all(app=app)
yield app
db.drop_all(app=app)
@pytest.fixture(scope="session")
def products(app):
with app.app_context():
return populate_db()
# each test runs on cwd to its temp dir
@pytest.fixture(autouse=True)
def go_to_tmpdir(request):
# Get the fixture dynamically by its name.
tmpdir = request.getfixturevalue("tmpdir")
# ensure local test created packages can be imported
sys.path.insert(0, str(tmpdir))
# Chdir only for the duration of the test.
with tmpdir.as_cwd():
yield