Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow then_do to take an async function if the mock is async #136

Closed
2 tasks
mcous opened this issue Jun 4, 2022 · 0 comments · Fixed by #138
Closed
2 tasks

Allow then_do to take an async function if the mock is async #136

mcous opened this issue Jun 4, 2022 · 0 comments · Fixed by #138
Labels
enhancement New feature or request

Comments

@mcous
Copy link
Owner

mcous commented Jun 4, 2022

The then_do method is a useful advanced method for some tests, especially when you're not in a position to change the API of a dependency at the time you're writing the test.

However, the then_do method only accepts a synchronous callable, even if the mock is an asynchronous mock. I've run into a few cases where this limitation was frustrating and I didn't have an immediately obvious path for better code structure within the constraints I needed to follow.

  • If a mock is async, it should accept an async callable as its then_do side-effect
  • Passing an async function to a sync mock should raise an exception
@mcous mcous added the enhancement New feature or request label Jun 4, 2022
mcous added a commit that referenced this issue Jun 5, 2022
mcous added a commit that referenced this issue Jun 5, 2022
@mcous mcous closed this as completed in #138 Jun 5, 2022
mcous added a commit that referenced this issue Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant