mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
tests: cache the jinja bytecode between unit tests
The jinja templates are compiled once per test session instead of once per test, using jinja cache system and a pytest fixture. https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.FileSystemBytecodeCache
This commit is contained in:
parent
a5f83de5ce
commit
3ac1bb8afe
1 changed files with 10 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from jinja2 import FileSystemBytecodeCache
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ihatemoney.babel_utils import compile_catalogs
|
from ihatemoney.babel_utils import compile_catalogs
|
||||||
|
@ -13,11 +14,19 @@ def babel_catalogs():
|
||||||
compile_catalogs()
|
compile_catalogs()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def jinja_cache_directory(tmp_path_factory):
|
||||||
|
return tmp_path_factory.mktemp("cache")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def app(request: pytest.FixtureRequest):
|
def app(request: pytest.FixtureRequest, jinja_cache_directory):
|
||||||
"""Create the Flask app with database"""
|
"""Create the Flask app with database"""
|
||||||
app = create_app(request.cls)
|
app = create_app(request.cls)
|
||||||
|
|
||||||
|
# Caches the jinja templates so they are compiled only once per test session
|
||||||
|
app.jinja_env.bytecode_cache = FileSystemBytecodeCache(jinja_cache_directory)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
request.cls.app = app
|
request.cls.app = app
|
||||||
|
|
Loading…
Reference in a new issue