Skip to content

Convert Async unit tests from unittest.TestCase to unittest.IsolatedAsyncioTestCase #711

Description

@christophertubbs

We have several unit tests floating about that test async functionality by manually handling an event loop. These tests should be run via async functions within IsolatedAsyncioTestCase classes rather than the standard TestCase that we're defaulting to.

There's a function I've got locally that's failure when called locally. The unit test looks like:

    def test_can_be_fulfilled_0_a(self):
        """ Test function against first job requirement for example 0 (requires all datasets, no preset fulfills). """
        ex_num = 0
        requirement_index = 0

        job = self.example_jobs[ex_num]
        result = self.loop.run_until_complete(
            self.data_inquery_util.can_be_fulfilled(job.data_requirements[requirement_index]))

        self.assertTrue(result[0])

If an IsolatedAsyncioTestCase were used, it could just be:

    def test_can_be_fulfilled_0_a(self):
        """ Test function against first job requirement for example 0 (requires all datasets, no preset fulfills). """
        ex_num = 0
        requirement_index = 0

        job = self.example_jobs[ex_num]
        result = await self.data_inquery_util.can_be_fulfilled(job.data_requirements[requirement_index])

        self.assertTrue(result[0])

There are other places where tests fail due to event loops being closed. Letting the unit tests handle this behavior natively rather than relying on our own implementations would help prevent/fix issues involved with just running the tests in the first place.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Low Hanging FruitThis should not take a lot of timeLow PriorityThis should not take the place of more important workgood first issueGood for newcomersrefactorCode Cleanup and Restructuring

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions