Test: Convert the slack and vmaas tests from unittest.IsolatedAsyncioTestCase to pytest style - #245
Open
AmaadMartin wants to merge 1 commit into
Open
Test: Convert the slack and vmaas tests from unittest.IsolatedAsyncioTestCase to pytest style#245AmaadMartin wants to merge 1 commit into
AmaadMartin wants to merge 1 commit into
Conversation
The three test modules subclassed unittest.IsolatedAsyncioTestCase. pytest does not apply fixtures or parametrize marks to a unittest.TestCase subclass, so anyone adding either to these classes gets a silent no-op. The base class also awaits its own coroutines, so pytest-asyncio never sees these tests and asyncio_mode does not cover them. Drop the base class, replace setUp with module-level fixtures and constants, replace every self.assert* with a bare assert, and mark every async test with an explicit @pytest.mark.asyncio. No test is added, removed, or renamed, and no assertion changes meaning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
N/A
Problem: Three test modules subclass
unittest.IsolatedAsyncioTestCase. pytest does not apply fixtures or@pytest.mark.parametrizeto aunittest.TestCasesubclass, so anyone who adds either to these classes gets a silent no-op. The base class also awaits its own coroutines, so pytest-asyncio never sees these tests and theasyncio_modesetting does not cover them.Solution: I converted the three modules to plain pytest classes.
setUpbecomes module-level fixtures for the mocks and module-level constants for the plain strings. Everyself.assert*becomes a bareassert, rewritten through an AST pass so no assertion changes meaning. Every async test now carries an explicit@pytest.mark.asyncioas its outermost decorator.Files:
tests/unittests/integrations/slack/test_slack_runner.pytests/unittests/integrations/vmaas/test_sandbox_client.pytests/unittests/integrations/vmaas/test_sandbox_computer.pyNo production source file changes. No test is added, removed, renamed, skipped, or weakened. 100
self.assert*calls became bare asserts: 2 / 49 / 49 per file. Marker counts are 3 / 19 / 26.Collection order changes, and this is unavoidable.
unittestsorts test methods alphabetically; pytest collects them in source order. The set of node IDs is byte-identical before and after (verified with--collect-only -q | sort | diff), and every test is independent, so only the order differs.Collision check: I listed the 100 open pull requests on this fork and read the diff of every plausibly adjacent one (#180, #179, #146, #177, #176, #170). None touches a file under
tests/unittests/integrations/slackor.../vmaas. #180 switchespyproject.tomltoasyncio_mode = strict; this change touches no config file and makes those three modules ready for that switch.Testing Plan
Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.
Unit Tests:
[x] I have added or updated unit tests for my change.
[x] All unit tests pass locally.
Baseline before the change and result after the change, on both async modes:
Formatting gate on the three files:
uv run pre-commit run --files <the three files>passes (isort, pyink, addlicense, compliance checks, codespell).Mutation checks. This change adds no code, so I proved instead that the converted assertions and the new markers still fail when the code under them breaks. Each mutation was reverted afterwards.
sandbox_client.py: CDP path"cdp"->"cdpX"test_make_cdp_requestFAILED (1 failed, 20 passed)sandbox_computer.py:_screen_size(1280, 720)->(1281, 720)test_initandtest_screen_sizeFAILED (2 failed, 31 passed)slack_runner.py:"_Thinking..._"->"_Working..._"slack_runner.py: error text"Sorry, I encountered an error"->"Oops, a problem occurred"test_handle_message_errorFAILED withAssertionError: assert 'Sorry, I encountered an error' in 'Oops, a problem occurred: Something went wrong'@pytest.mark.asyncio(test_screen_size), run strict modeasync def functions are not natively supported.The last row is the one that matters for the markers. Under the current
asyncio_mode = autoa missing marker is invisible; strict mode is what proves each marker is real.CI. All 14 test jobs pass: Unit Tests on Python 3.10 to 3.14, Mypy Check on 3.10 to 3.13, and A2A v0.3 Tests on 3.10 to 3.14.
Pre-commit Linterfails, and the cause is unrelated to this change. Every formatting hook passes (isort,pyink,addlicense,ruff,pyproject-fmt,ADK Compliance Checks,mdformat,codespell). The single failing hook isupdate-constraints, which regeneratesconstraints-3.10.txtthroughconstraints-3.14.txtwith today's--exclude-newerdate instead of the recorded2026-07-24. This change touches no dependency, nopyproject.toml, and no constraints file. The same job fails the same way on unrelated open pull requests #243, #241 and #238.Manual End-to-End (E2E) Tests:
Not applicable. This change touches only test files and adds no runtime behaviour. The strict-mode run above is the meaningful manual check.
Checklist
[x] I have read the CONTRIBUTING.md document.
[x] I have performed a self-review of my own code.
[x] I have commented my code, particularly in hard-to-understand areas.
[x] I have added tests that prove my fix is effective or that my feature works.
[x] New and existing unit tests pass locally with my changes.