Skip to content

Support async functions under patch decorator#135

Merged
wolever merged 1 commit intowolever:masterfrom
Ronserruya:async_patch_support
Mar 2, 2023
Merged

Support async functions under patch decorator#135
wolever merged 1 commit intowolever:masterfrom
Ronserruya:async_patch_support

Conversation

@Ronserruya
Copy link

Supports the @patch decorator with parametrized when used with async methods
Its a pretty simple fix, I also tried to add tests but failed since

  1. Nose can't do async and I can't make it skip the test
  2. All the python 2 runners instantly fail on SyntaxError even though I put the tests under an IF PY_3.8

If you do manage to make the tests work, this is a simple test I wrote
For what its worth, it did pass all of the tests with 3.6+ (apart from nose), and I tested it with several patches as well

if sys.version_info.major == 3 and sys.version_info.minor >= 8:
    from unittest import IsolatedAsyncioTestCase

    class TestAsyncParameterizedExpandWithNoMockPatchForClass(IsolatedAsyncioTestCase):
        expect([
            "test_one_async_function_patch_decorator('foo1', 'umask')",
            "test_one_async_function_patch_decorator('foo0', 'umask')",
            "test_one_async_function_patch_decorator(42, 'umask')",
        ])

        @parameterized.expand([(42,), "foo0", param("foo1")])
        @mock.patch("os.umask")
        async def test_one_async_function_patch_decorator(self, foo, mock_umask):
            missing_tests.remove("test_one_async_function_patch_decorator(%r, %r)" %
                                 (foo, mock_umask._mock_name))

P.s you really should add some contributing guide explaining how to set the project up, and how to test it :)

wolever added a commit that referenced this pull request Mar 2, 2023
wolever added a commit that referenced this pull request Mar 2, 2023
Support async functions under patch decorator (updates to #135)
@wolever wolever merged commit 6bba7bf into wolever:master Mar 2, 2023
@wolever
Copy link
Owner

wolever commented Mar 2, 2023

Hey! Thank you very much for this! I've got the test added and a couple more things fixed here: #151

And I'll be getting a CONTRIBUTING doc up shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants