I am trying to create a test for set some values in a device and then query them from device to assert that they are equal several times with specific time intervals. But for this to work I need to run query and assert things async because I cannot wait for a response to continue. But I couldn't use then
functions with pytest.mark.asyncio
. How can I use both of them at the same time?
I first tried this but I get "coroutine 'test_get_value' was never awaited" error.
@pytest.mark.asyncio
@then(parsers.parse("The query result for {setting} is {value:n}"))
@then(parsers.parse("The query result for {setting} is {value:bool}", extra_types={"bool": bool}))
async def test_get_value(destination, setting, value):
responses = await run_queries(destination, setting)
for response in responses:
assert response == value
run_queries funciton is something like this. There are some custom classes that I use that is unrelated to my problem because they work without any problem.
async def run_queries(destination: int, query_name: str, connection_file: str) -> List[int]:
# I create a custom message object with query_name, connection file, and destination
responses = client.execute(message) # Here the query is executed and responses are collexted works without a problem
query_result = []
for response in responses:
if response.tid == tid: # To check that I get the correct responses
query_result.append(response.value[0])
return query_result
Then without changing run_queries I tried to use a scenario mark but in that case scenario is not running at all
@scenario('../features/scenario_fixture.feature', 'Hope this works')
@pytest.mark.asyncio
def test_query():
pass
and Feature file includes only this
Feature: Scenario test
Scenario: Hope this works
Then The query result for setting is 100