0

If it is not async function and just return host_output function and another_host_output, the test were all passed. However, when I changed it with the async function, the tests started failing. How can I solve the value error in this situation?

async def get_host_output(host, output=True):
  
  // some more code here

  if output:
     async for i in host_output(hosts=host):
          yield i
  else: 
     async for j in another_host_output(hosts=host):
          yield j

test case

def test_with_host():
   
  // some codes here
  mocking_response= mock_response()
  with.pytest.raises(ValueError):
      mocking_response.get_host_output(hosts=host) // return asynchronous gernerator object
  // tried to input a fake host to trigger the Value error, but still failed.
  assert mocking_response.get_host_output(hosts='123')
Ckate
  • 43
  • 5
  • `await mocking_response.get_host_output(hosts=host)`? See https://stackoverflow.com/questions/23033939/how-to-test-python-3-4-asyncio-code – Samwise Mar 07 '22 at 01:32
  • @Samwise I got an typeError :object aysnc_generator can't be use in "await " expression. I tried to use, res = async for mocking_response.get_host_output(hosts=host), but it didn't work. – Ckate Mar 07 '22 at 01:50

0 Answers0