Skip to content

Instantly share code, notes, and snippets.

@Apakottur
Last active January 28, 2022 16:45
Show Gist options
  • Save Apakottur/cc0b0ae6bd982dd1c2f48880ce8d9749 to your computer and use it in GitHub Desktop.
Save Apakottur/cc0b0ae6bd982dd1c2f48880ce8d9749 to your computer and use it in GitHub Desktop.
Coverage bug (SQLAlchemy + aiosqlite + strawberry-graphql)
version: "3.8"
services:
test:
build:
context: .
FROM python:3.10.1-slim-bullseye
RUN pip install \
sqlalchemy==1.4.31 \
strawberry-graphql==0.95.1 \
coverage==6.3.0 \
aiosqlite==0.17.0
WORKDIR /src/
COPY example.py run.py /src/
CMD ["python", "run.py"]
import asyncio
from sqlalchemy import sql
import strawberry
from sqlalchemy.ext.asyncio import create_async_engine
@strawberry.type
class Mutation:
@strawberry.field
async def my_mutation(info) -> int:
engine = create_async_engine("sqlite+aiosqlite://")
async with engine.connect() as connection:
await connection.execute(sql.text("SELECT 1"))
print("This is not covered")
return 123
@strawberry.type
class Query:
garb: int
schema = strawberry.Schema(query=Query, mutation=Mutation)
async def test_bug() -> None:
await schema.execute("mutation { myMutation }")
asyncio.run(test_bug())
import coverage
cov = coverage.Coverage(include="example.py", timid=True)
cov.start()
import example
cov.stop()
cov.save()
cov.report(show_missing=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment