Skip to content

How to write tests? #136

Answered by collerek
vladisa88 asked this question in Q&A
Mar 24, 2021 · 5 comments · 10 replies

You must be logged in to vote

I depends if you are testing with client or without.

If you do only unit/logic testing this should work:

# fixture
@pytest.fixture(autouse=True, scope="module")  # adjust your scope
def create_test_database():
    engine = sqlalchemy.create_engine(DATABASE_URL)
    metadata.drop_all(engine) # i like to drop also before - even if test crash in the middle we start clean
    metadata.create_all(engine)
    yield
    metadata.drop_all(engine)

# actual test - note to test async you need pytest-asyncio and mark test as asyncio
@pytest.mark.asyncio
async def test_actual_logic():
    async with database:  # <= note this is the same database that used in ormar Models
        ... (logic)

If you wa…

Replies: 5 comments 10 replies

You must be logged in to vote
3 replies
@vladisa88

@collerek

@vladisa88

Answer selected by collerek

You must be logged in to vote
5 replies
@pawamoy

@collerek

@dbatten5

@pawamoy

@pawamoy

You must be logged in to vote
2 replies
@collerek

@5h44n

You must be logged in to vote
0 replies

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants