Skip to content

Instantly share code, notes, and snippets.

@viniciusao
Created June 24, 2022 16:11
Show Gist options
  • Save viniciusao/925cee2dd357602b3bfcd2f434acf5a3 to your computer and use it in GitHub Desktop.
Save viniciusao/925cee2dd357602b3bfcd2f434acf5a3 to your computer and use it in GitHub Desktop.
Pytest mock database: Fixture
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