Skip to content

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Jan 10, 2026

This pull request re-enables and refactors the test_c_char in test_outparam.py, which was previously skipped "for misterious reasons"(3cadc71, #298, #271).
It is unclear why this test has started working again without any direct changes. Our best guess is that a combination of CPython bugfix releases and community-led fixes like #473 has resolved the underlying issue.

Test Enhancement:

The re-enabled test_c_char now provides verification for the correct handling pointers and their associated memory management within COM interoperability.
The explicit checks for malloc.DidAlloc directly address the nuances of COM memory ownership.

Refactoring Value:

The test code has been improved for clarity, robustness, and maintainability.

  • The use of self.subTest provides granular feedback for each test case, making it easier to identify and debug specific failures.
  • Conversion of ValueError to direct assert statements aligns with idiomatic Python testing practices, simplifying test logic.
  • Conversion of print statements to logger.debug allows for better control over debugging output, improving the signal-to-noise ratio during test execution.
  • Removal of redundant str conversion and irrelevant comments streamlines the codebase.

The `test_c_char` in `test_outparam.py` was previously skipped due to
"failing for mysterious reasons". It now passes without modifications.
This suggests that underlying issues might have been resolved by this
package's community or within CPython over the past few years.
…param`.

Removed the `text_type = str` assignment and its usage in `comstring` function.
This change eliminates a redundant `str` conversion that remained from Python
2/3 version bridging.
Replaced `print` statements with `logger.debug` in `test_outparam.py` to allow
for more granular control and suppression of debug messages.
…in `test_outparam`.

Changed the memory allocation check in `test_outparam.py` from raising a
`ValueError` to using an `assert` statement. In test code, avoiding `if`
branches is preferred.
… allocator.

Added an assertion to `test_outparam.py` to verify that `c_wchar_p`'s
constructor does not allocate memory using `CoTaskMemAlloc`. This ensures
the memory is not identified as COM-allocated.
This check is vital to prevent the patched `__ctypes_from_outparam__` from
attempting to free unmanaged memory, which it expects to be COM-allocated.
Removed a commented-out `BSTR` instantiation from `test_outparam.py`.
While its presence might have been intended to prevent some type definition
regression, it felt largely unrelated to the core purpose of this specific
test and was therefore removed for clarity.
…ocation.

Refactored `test_c_char` in `test_outparam.py` to utilize `self.subTest` for
improved test granularity. The test now explicitly verifies memory allocation
status using `malloc.DidAlloc` before and after calling
`__ctypes_from_outparam__`, ensuring correct memory deallocation behavior.
Old commented-out debug statements were also removed.
Removed the `TODO` comment in `comtypes/test/test_outparam.py` regarding
"untested changes" and "global effects on other tests". This comment is
no longer relevant due to recent improvements and the unskipping of
`test_c_char`.
Corrected a typo in the function name `from_outparm` to `from_outparam`
within `test_outparam.py`.
@junkmd junkmd added this to the 1.4.15 milestone Jan 10, 2026
@junkmd junkmd added the tests enhance or fix tests label Jan 10, 2026
@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.55%. Comparing base (5932fe9) to head (e741555).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
+ Coverage   85.40%   85.55%   +0.14%     
==========================================
  Files         126      126              
  Lines       12018    12022       +4     
==========================================
+ Hits        10264    10285      +21     
+ Misses       1754     1737      -17     

☔ 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 925c5cb into enthought:main Jan 10, 2026
52 checks passed
@junkmd junkmd deleted the revive_test_outparam branch January 10, 2026 05:07
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