attribute error: 'nonetype' object has no attribute 'empty' for async await

904 views Asked by At
class a(self):
  async def x(self, p1, p2):
     await connection.fetch(p1)
     ....
     return df

  async def y(self, p3, p4):
     df = await self.x(x1, x2)
     if not df.empty:
       # code

How to write a test method for y()? After mock of x(), getting this error: attribute error: 'nonetype' object has no attribute 'empty'

test_y.py:

import asyncio 

def x_mock():
   ...
   return df

def test_y(mocker): 
   ...
   mocker.patch('a.x', return_value=x_mock())
   asyncio.run(y(p3, p4))

x_mock() is basically creating a dataframe

1

There are 1 answers

0
JoseKilo On

Following up from the comments, try using:

mocker.patch(..., new_callable=mocker.AsyncMock)