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
Discussion options

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

Comment options

You must be logged in to vote
3 replies
@vladisa88
Comment options

@collerek
Comment options

@vladisa88
Comment options

Answer selected by collerek
Comment options

You must be logged in to vote
5 replies
@pawamoy
Comment options

@collerek
Comment options

@dbatten5
Comment options

@pawamoy
Comment options

@pawamoy
Comment options

Comment options

You must be logged in to vote
2 replies
@collerek
Comment options

@5h44n
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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