wolever / parameterized

Parameterized testing with any Python test framework
Other
833 stars 105 forks source link

Support async functions under patch decorator #135

Closed Ronserruya closed 1 year ago

Ronserruya commented 2 years ago

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 commented 1 year ago

Hey! Thank you very much for this! I've got the test added and a couple more things fixed here: https://github.com/wolever/parameterized/pull/151

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