Fastapi: [QUESTION]: pytest migrating from Flask: app.config

Created on 13 Oct 2019  Â·  3Comments  Â·  Source: tiangolo/fastapi

My previous pytest file was:

import os
import tempfile

import pytest

from flaskr import flaskr


@pytest.fixture
def client():
    db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
    flaskr.app.config['TESTING'] = True
    client = flaskr.app.test_client()

    with flaskr.app.app_context():
        flaskr.init_db()

    yield client

    os.close(db_fd)
    os.unlink(flaskr.app.config['DATABASE'])

but with FastAPI there is no app.config? How to resolve this?

question

All 3 comments

You may try using the search this was answered previously

Le dim. 13 oct. 2019 à 3:24 PM, Sebastian Cheung CQF <
[email protected]> a écrit :

My previous pytest file was:

import os
import tempfile

import pytest

from flaskr import flaskr

@pytest.fixture
def client():
db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
flaskr.app.config['TESTING'] = True
client = flaskr.app.test_client()

with flaskr.app.app_context():
    flaskr.init_db()

yield client

os.close(db_fd)
os.unlink(flaskr.app.config['DATABASE'])

but with FastAPI there is no app.config? How to resolve this?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tiangolo/fastapi/issues/619?email_source=notifications&email_token=AAINSPSU5TRPIBB5YKQLKCDQOMOQFA5CNFSM4JAG65YKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HRN5C2Q,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAINSPRGIGE2DWH6C5XLB63QOMOQFANCNFSM4JAG65YA
.

There's a section in the docs about testing a database, that's probably what you're looking for: https://fastapi.tiangolo.com/advanced/testing-database/

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Was this page helpful?
0 / 5 - 0 ratings