I'm encountering a deprecation warning related to Jinja2Templates when running pytest tests with starlette>=0.28.0 :
.venv/lib/python3.11/site-packages/starlette/templating.py:106: DeprecationWarning: Extra environment options are deprecated. Use a preconfigured jinja2.Environment instead.
warnings.warn(
This warning does not appear when installing starlette==0.27.0
According to the Starlette 0.28.0 release notes, the **env_options parameter in Jinja2Templates has been deprecated in favor of the new env parameter. The relevant pull request #2159 explains this change.
It seems likely that Starlette Admin (or other dependencies) are still using the deprecated **env_options, causing the warning when running tests with Starlette 0.28.0.
Steps to Reproduce:
-
Project Structure:
.
├── app.py
├── requirements-deprecation-warning.txt
├── requirements-no-warnings.txt
└── test_app.py
-
Source Code:
app.py:
from fastapi import FastAPI
from starlette_admin.contrib.sqlmodel import Admin
from sqlmodel import SQLModel, create_engine
DATABASE_URL = "sqlite:///./test.db"
engine = create_engine(DATABASE_URL, echo=True)
SQLModel.metadata.create_all(engine)
app = FastAPI()
admin = Admin(engine, title="Simple Admin")
admin.mount_to(app)
test_app.py:
import pytest
from fastapi.testclient import TestClient
from app import app
@pytest.fixture(scope="module")
def client():
with TestClient(app) as client:
yield client
def test_admin_page(client):
response = client.get("/admin")
assert response.status_code == 200
assert "Simple Admin" in response.text
-
Requirements Files:
requirements-deprecation-warning.txt:
fastapi
sqlmodel
uvicorn
starlette-admin
jinja2
sqlalchemy
starlette==0.28.0
pytest
httpx==0.24.1
requirements-no-warnings.txt:
fastapi
sqlmodel
uvicorn
starlette-admin
jinja2
sqlalchemy
starlette==0.27.0
pytest
httpx==0.24.1
-
Reproduce the Warning:
pip install -r requirements-deprecation-warning.txt
pytest
Result: Deprecation Warning
pip install -r requirements-no-warnings.txt
pytest
Result: All tests pass without warnings.
I'm encountering a deprecation warning related to
Jinja2Templateswhen runningpytesttests withstarlette>=0.28.0:This warning does not appear when installing
starlette==0.27.0According to the Starlette 0.28.0 release notes, the
**env_optionsparameter inJinja2Templateshas been deprecated in favor of the newenvparameter. The relevant pull request #2159 explains this change.It seems likely that Starlette Admin (or other dependencies) are still using the deprecated
**env_options, causing the warning when running tests with Starlette 0.28.0.Steps to Reproduce:
Project Structure:
Source Code:
app.py:test_app.py:Requirements Files:
requirements-deprecation-warning.txt:requirements-no-warnings.txt:Reproduce the Warning:
Result: Deprecation Warning
Result: All tests pass without warnings.