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

Test Runner: detect async issues for unittest.TestCase #232

Open
fornellas opened this issue Sep 1, 2020 · 1 comment
Open

Test Runner: detect async issues for unittest.TestCase #232

fornellas opened this issue Sep 1, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request Test Runner

Comments

@fornellas
Copy link
Contributor

fornellas commented Sep 1, 2020

Python provides IsolatedAsyncioTestCase to run tests as async def test* methods. however, people often confuse this class with regular unittest.TestCase, and in such case, the test methods being coroutines, they will be called as if they were sync, never to be awaited, and tests will go green with no failures.

We already detect such cases (and others) for TestSlide's DSL tests. Lets update the test runner, so it can also detect such issues when running unittests.

Currently to detect async issues from TestSlide DSL we:

  • Run the event loop with debug.
  • Intercept log & warnings.

As long as the event loop is ran in debug, we can catch these. We can also add more patching to the event loop to not require debug (and perhaps an upstream patch for that as well). Eg: we could have at the event loop class level callbacks for async issues.

@fornellas fornellas self-assigned this Sep 1, 2020
@fornellas fornellas added Test Runner enhancement New feature or request labels Sep 1, 2020
@fornellas
Copy link
Contributor Author

I tested Python 3.7 & 3.8:

  • With debug=False:
    • Both issue warning on not awaited coroutines.
    • None log slow execution.
  • With debug=True:
    • Both log slow execution.

So, we can make the test runner itself intercept the forgotten await warning, neat.

For the slow execution, we can patch BaseEventLoop._run_once to set self._debug = True only when the method is running, so we can get this log message, without enabling debugging for everything.

@fornellas fornellas changed the title Test Runner: fail on unittest not awaited coroutines Test Runner: fail on unittest not async issues Oct 16, 2020
@fornellas fornellas changed the title Test Runner: fail on unittest not async issues Test Runner: detect async issues for unittest.TestCase Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Test Runner
Projects
None yet
Development

No branches or pull requests

1 participant