From 4c4dd78a2cc8ab137de88727ea50951381ebc730 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sat, 28 Dec 2024 09:01:24 +0900 Subject: [PATCH] Add the `Release` doctest. --- docs/source/com_interfaces.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/source/com_interfaces.rst b/docs/source/com_interfaces.rst index af4907c9..056b0a8a 100644 --- a/docs/source/com_interfaces.rst +++ b/docs/source/com_interfaces.rst @@ -92,8 +92,10 @@ The ``IUnknown`` as a Python class if ``Release`` is called at the aforementioned timing, it may raise an ``OSError``. - .. sourcecode:: pycon + .. doctest:: + >>> import contextlib + >>> import io >>> from comtypes.client import CreateObject, GetModule >>> GetModule('UIAutomationCore.dll') # doctest: +ELLIPSIS @@ -103,7 +105,11 @@ The ``IUnknown`` as a Python class >>> iuia.Release() 0 - >>> del iuia # doctest: +ELLIPSIS + >>> stderr = io.StringIO() + >>> with contextlib.redirect_stderr(stderr): + ... del iuia + ... + >>> print(stderr.getvalue()[:-1]) # doctest: +ELLIPSIS Exception ignored in: Traceback (most recent call last): ...