crickets-and-comb / crickets-and-comb/reference_package

Make example test DB.

Open
#27 0 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted test coverage
Dominant language
Python
Stars
1
Forks
2
PR merge metrics
No merged PRs in 30d

Description

It would be nice to have an example test that spins up a temporary DB to run tests with. Something like:

```
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base, User

@pytest.fixture
def in_memory_db():
# Spin up a new in-memory SQLite DB
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()

yield session

session.close()

def test_create_user(in_memory_db):
user = User(name="Alice")
in_memory_db.add(user)
in_memory_db.commit()

retrieved = in_memory_db.query(User).filter_by(name="Alice").first()
assert retrieved is not None
assert retrieved.name == "Alice"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.