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
如何为 y() 编写测试方法?在模拟 x() 后,出现此错误: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()
基本上是创建一个数据框