Skip to content

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Jan 20, 2026

Overview

This pull request enhances the tests for object creation functions (CreateObject, CoGetObject, GetActiveObject).
The changes remove reliance on mocking in dynamic dispatch tests, ensuring that real COM object interactions are validated.

Comprehensive CoGetObject Testing

The CoGetObject function now has dedicated, comprehensive tests ensuring it correctly returns both specific COM interfaces and dynamic dispatch objects.

Improved Dynamic Dispatch Behavior Verification

Tests for dynamic.Dispatch and lazybind.Dispatch have been refactored to use live COM objects instead of mocks. This change moves from simulated scenarios to real-world COM interactions, thus increasing the reliability of these core dynamic dispatch mechanisms.

Stricter API Usage Enforcement

New tests ensure that CreateObject, CoGetObject, and GetActiveObject correctly raise ValueError when dynamic=True is used in conjunction with an explicit interface argument.

Refactor `dynamic.Dispatch` tests in `test_client_dynamic.py` by removing `mock`
usage. Tests now directly create COM objects with `CreateObject` to validate
`lazybind.Dispatch` and `dynamic._Dispatch` instances more accurately.
…roduce `Test_lazybind_Dispatch`.

Adjust index access assertion in `lazybind.Dispatch` tests to reflect its
`None` return for non-existent keys, contrasting with `dynamic._Dispatch`'s
`IndexError`. Add comments explaining these behaviors.
…s tests.

Add specific tests for `dynamic.Dispatch` and `lazybind.Dispatch` to verify
behavior when attempting to access non-existent members. `dynamic.Dispatch`
is expected to raise `COMError` with `hresult.DISP_E_UNKNOWNNAME`, while
`lazybind.Dispatch` should raise `NameError`.
… and `lazybind.Dispatch`.

These tests verify property and method access on the `WindowsInstaller.Installer`
COM object, ensuring proper interaction with real-world COM components.
… `dynamic=True`.

This change adds a test case to `Test_MSVidCtlLib` in `test_getactiveobj.py`
to confirm that `comtypes.client.GetActiveObject` raises a `ValueError`
when both `dynamic=True` and an `interface` are provided simultaneously.
Additionally, it verifies that `GetActiveObject` correctly returns a
`comtypes.client.lazybind.Dispatch` object with an identical hash to the
original object when `dynamic=True` is specified.
…th `interface`.

This test case confirms that `comtypes.client.CreateObject` correctly raises
a `ValueError` when an `interface` is provided alongside `dynamic=True`,
preventing a potential misuse of the API.
Introduces a new test class `Test_CoGetObject` to thoroughly verify the
functionality of `comtypes.client.CoGetObject`. It includes test cases
for successfully returning an interface pointer and a dynamic dispatch
object, as well as confirming that a `ValueError` is raised when both
`dynamic=True` and an `interface` are simultaneously provided.
@junkmd junkmd added this to the 1.4.16 milestone Jan 20, 2026
@junkmd junkmd added the tests enhance or fix tests label Jan 20, 2026
@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.41%. Comparing base (07ab1f4) to head (a590e43).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #909      +/-   ##
==========================================
+ Coverage   86.24%   86.41%   +0.16%     
==========================================
  Files         132      132              
  Lines       12334    12399      +65     
==========================================
+ Hits        10638    10714      +76     
+ Misses       1696     1685      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd junkmd merged commit ce14575 into enthought:main Jan 20, 2026
141 of 150 checks passed
@junkmd junkmd deleted the client_dynamic_no_mock_tests branch January 20, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant