tests: speed up unit tests by caching the jinja bytecode between tests

This commit is contained in:
Éloi Rivard 2024-04-16 12:46:53 +02:00
parent 1decf162b4
commit 1080952a75
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184

View file

@ -3,6 +3,7 @@ import os
import pytest import pytest
from babel.messages.frontend import compile_catalog from babel.messages.frontend import compile_catalog
from flask_webtest import TestApp from flask_webtest import TestApp
from jinja2 import FileSystemBytecodeCache
from jinja2 import StrictUndefined from jinja2 import StrictUndefined
from pytest_lazyfixture import lazy_fixture from pytest_lazyfixture import lazy_fixture
from werkzeug.security import gen_salt from werkzeug.security import gen_salt
@ -151,9 +152,15 @@ def configuration(smtpd):
return conf return conf
@pytest.fixture(scope="session")
def jinja_cache_directory(tmp_path_factory):
return tmp_path_factory.mktemp("cache")
@pytest.fixture @pytest.fixture
def app(configuration, backend): def app(configuration, backend, jinja_cache_directory):
app = create_app(configuration, backend=backend) app = create_app(configuration, backend=backend)
app.jinja_env.bytecode_cache = FileSystemBytecodeCache(jinja_cache_directory)
backend.install(app.config) backend.install(app.config)
with app.test_request_context(): with app.test_request_context():
yield app yield app