asynctest icon indicating copy to clipboard operation
asynctest copied to clipboard

Define the behavior and implement CoroutineMock(side_effect=a_coroutine)

Open Martiusweb opened this issue 7 years ago • 1 comments

Currently, the behavior when calling a CoroutineMock with a coroutine as side_effect is undefined.

It raises an exception with Python 3.6 and seems to run the coroutine with Python 3.5 (at least with an old style coroutine).

The behavior of using a coroutine with side_effect must be defined and implemented. On suggestion is to run the coroutine. It seems useless to wrap an actual coroutine with CoroutineMock, but I see at least two use cases:

  • we want to patch an actual coroutine function with a sleep,
  • we want to wrap the coroutine function with a CoroutineMock to use CoroutineMock's assert methods.

Martiusweb avatar Jan 16 '17 20:01 Martiusweb

One important point related to this is:

When the side_effect will occur?

In a ordinary call or in a await?

for example:


a = CoroutineMock(side_effect=Exception)

a() # raises the exception
await a() # `a` would be never awaited

dnp1 avatar Jul 17 '18 21:07 dnp1