Created
June 24, 2022 16:11
-
-
Save viniciusao/925cee2dd357602b3bfcd2f434acf5a3 to your computer and use it in GitHub Desktop.
Pytest mock database: Fixture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from pytest_mock_resources import create_postgres_fixture | |
from sqlalchemy.orm import Session | |
from model import Actor, User | |
pg = create_postgres_fixture( | |
*[Actor, User] | |
) | |
@pytest.fixture | |
def session_same_name(pg): | |
with Session(pg) as s: | |
models = { | |
'User': User(name='mock'), | |
'Actor': Actor(name='mock') | |
} | |
s.bulk_save_objects(models.values()) | |
yield s, models |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment