Last active
January 28, 2022 16:45
-
-
Save Apakottur/cc0b0ae6bd982dd1c2f48880ce8d9749 to your computer and use it in GitHub Desktop.
Coverage bug (SQLAlchemy + aiosqlite + strawberry-graphql)
This file contains hidden or 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
version: "3.8" | |
services: | |
test: | |
build: | |
context: . | |
This file contains hidden or 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
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"] |
This file contains hidden or 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 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()) |
This file contains hidden or 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 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