samedi 17 avril 2021

How to loop into test using pytest?

I would like to write a login test where the precondition is to make a few authentication requests that need to be done. Each time the JSON with the error msg "invalid" is returned. Then the user is blocked and the error msg is moving to "blocked".

I tried like that:

@pytest.fixture
def event_loop():
    loop = asyncio.get_event_loop()
    yield loop
    loop.close()

def test_block(event_loop):
    r = login("login", variables.INVALID_PASSWORD)
    assert r.json()['error'] == event_loop.run_until_complete((f'User was blocked.'))
    event_loop.run_until_complete

Aucun commentaire:

Enregistrer un commentaire