[Python] Python3 and pytest: jinja2.exceptions.TemplateNotFound:

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    i'm creating some unit tests and i'm facing this issue


    FAILED test_views_home.py::test_index - jinja2.exceptions.TemplateNotFound: index.html
    ​

    this is part of my testing code:

    templates = Jinja2Templates('templates')

    def test_index():
    @router.get('/', include_in_schema=False)
    async def index(request: Request):
    return templates.TemplateResponse('index.html', {'request': request})

    client = TestClient(router)
    response = client.get("/")
    assert response.status_code == 200
    assert '<!DOCTYPE html>' in response.text


    and this is my folder structure:

    root/
    ├── views/
    │ ├── index.py
    ├── templates/
    │ ├── index.html
    ├── tests/
    │ ├── test_sorullo.py


    i got:


    FAILED test_views_home.py::test_index - jinja2.exceptions.TemplateNotFound: index.html
    ​

    I'm guessing i'm putting wrong

    templates = Jinja2Templates('templates')


    but i couldn't figure it out. I didn't find anything similar searching. What i'm doing wrong?

    thanks!

    Continue reading...

Compartilhe esta Página