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 mock_callable() to work with async functions #8

Closed
wants to merge 1 commit into from

Conversation

fornellas
Copy link
Contributor

Add support for mock_callable() to wok on async methods:

import testslide, asyncio, inspect

class Test(object):
  @classmethod
  async def m(self):
    return 'original'

class TestAsync(testslide.TestCase):
  def test_async(self):
    self.assertEqual(
      asyncio.run(Test.m()),
      'original'
    )

    self.mock_callable(Test, 'm')\
      .to_return_value('mock')
    
    self.assertEqual(
      asyncio.run(Test.m()),
      'mock'
    )

In principle, this should work for all cases (functions, instance methods, class methods etc), but we need to add test coverage.

Things to consider:

  • with_implementation and with_wrapper should ideally also accept async methods as arguments.
  • to_call_original might be broken for async, we need a test there.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Oct 11, 2018
@fornellas fornellas closed this Apr 23, 2019
@fornellas fornellas deleted the async_mc branch April 23, 2019 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants