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

Is it possible to write unittests for async functions using @parameterized.expand? #137

Closed
SadiaAfrinPurba opened this issue May 9, 2022 · 6 comments

Comments

@SadiaAfrinPurba
Copy link

Hi,

I want to test the async functions using the @parameterized.expand decorator. There is no error while executing the tests, but it shows zero test coverage.

I'm using the @async_test decorator to test the async functions and without @parameterized.expand they work fine, meaning that it shows 100% code coverage.

from aioitertools.tests.helpers import async_test

class TestService(TestCase):
    def setUp(self) -> None:
        self.mock_query_details = {"column_id": 0}

    @parameterized.expand([
        ({"col1": ["", "a", "b", "c", "d", "", "", ""], "cluster": [0, 1, 1, 1, 1, 0, 0, 0]},
         [['a'], ['b'], ['c'], ['d']]),
        ({"col1": [" ", "a", "b", "c", "d", " ", " ", " "], "cluster": [0, 1, 1, 1, 1, 0, 0, 0]},
         [['a'], ['b'], ['c'], ['d']]),
    ])
    @async_test
    async def test_function(self, mock_data, expected):
        data_frame = pd.DataFrame(mock_data)
        num_rows = 4

        service = Service()
        actual = await service.function(query_detail=self.mock_query_details, data_frame=data_frame,
                                                       num_rows=num_rows)

        self.assertCountEqual(actual, expected)



Do I need to follow any extra steps for using the @parameterized.expand decorator to test the async function?

@dbungert
Copy link

Depending on python version this may work when paried with unittest.IsolatedAsyncioTestCase, or you may run into python/cpython#101486

I started some fixes for this - master...dbungert:parameterized:expand-async - but am unsure about handling of pre-python 3.5.

@wolever
Copy link
Owner

wolever commented Mar 2, 2023

This has been added in 0.9.0 thanks to , which will be on pypi in a day or so (#135; thanks @Ronserruya!)

@wolever wolever closed this as completed Mar 2, 2023
@kkozmic
Copy link

kkozmic commented Mar 20, 2023

I too am waiting for this. Anything else holding 0.9.0 up @wolever ?

@gaby
Copy link

gaby commented Mar 22, 2023

@wolever Any chance to get v0.9.0 released? Thanks!

@wolever
Copy link
Owner

wolever commented Mar 27, 2023

It's up! https://pypi.org/project/parameterized/0.9.0/

@gaby
Copy link

gaby commented Mar 27, 2023

@wolever Thanks!

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

No branches or pull requests

5 participants