Skip to content

Database testing #530

Answered by dantownsend
Anton-Karpenko asked this question in Q&A
May 31, 2022 · 2 comments · 7 replies
Discussion options

You must be logged in to vote

Hi @Anton-Karpenko, I'm glad you're enjoying Piccolo.

When testing async code, there are a few ways to go about it. If you use piccolo tester run it just calls Pytest under the hood.

I see from the FastAPI docs that it recommends using the pytest.mark.anyio decorator. Is this what you're currently using?

I tend to use pytest-asyncio instead, as I don't use Trio.

# test_app.py

import pytest

from my_app.tables import MyTable


@pytest.mark.asyncio
async def test_foo():
    rows = await MyTable.select()
    assert len(rows) == 0

If you prefer using Python's builtin TestCase, you can also do things like this:

# test_app.py

from unittest import TestCase

import pytest
from piccolo.utils.sync 

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@dantownsend
Comment options

@Anton-Karpenko
Comment options

@dantownsend
Comment options

@Anton-Karpenko
Comment options

@dantownsend
Comment options

Answer selected by Anton-Karpenko
Comment options

You must be logged in to vote
1 reply
@dantownsend
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants