question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[pytest integration] (Windows fatal exception: code 0x80010108) @ comtypes

See original GitHub issue

Description

Running pytest with pywinauto causes an exception in shutdown of comtypes. Tests are collected / run correctly, but at the end there’s always an exception output.

This breaks test discovery in VSCode, though I can work around it by moving import statements to the inside of fixtures / functions.

I am not sure if this is an issue with how I am using pytest and pywinauto, or its a bug.

I tried python 3.6 (Visual Studio 2017), 3.7 (Anaconda3), and 3.8 (python.org).

Example code

File test_case.py

import pytest
from pywinauto.application import Application

def test_case():
    assert True

Test discovery

In the directory containing test_case.py python -m pytest --collect-only

Output

========================================================================================= test session starts ========================================================================================== 
platform win32 -- Python 3.8.0, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
rootdir: C:\Users\Yujin\Desktop\pytest_pywinauto
collected 1 item
<Module test_case.py>
  <Function test_case>

=========================================================================================== warnings summary =========================================================================================== 
C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py:2
  C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp, sys, os

-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================================================================================== 1 warning in 0.17s ========================================================================================== 
Windows fatal exception: code 0x80010108

Thread 0x0000625c (most recent call first):
  File "C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\comtypes\__init__.py", line 185 in shutdown
Windows fatal exception: code 0x80010108

Thread 0x0000625c (most recent call first):
  File "C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\comtypes\__init__.py", line 185 in shutdown

Running the test

python -m pytest

C:\Users\Yujin\Desktop\pytest_pywinauto>"C:/Program Files/Python38/python.exe" -m pytest
========================================================================================= test session starts ========================================================================================== 
platform win32 -- Python 3.8.0, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
rootdir: C:\Users\Yujin\Desktop\pytest_pywinauto
collected 1 item                                                                                                                                                                                         

test_case.py .                                                                                                                                                                                    [100%] 

=========================================================================================== warnings summary =========================================================================================== 
C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py:2
  C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp, sys, os

-- Docs: https://docs.pytest.org/en/latest/warnings.html
===================================================================================== 1 passed, 1 warning in 0.18s ===================================================================================== 
Windows fatal exception: code 0x80010108

Thread 0x00005e8c (most recent call first):
  File "C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\comtypes\__init__.py", line 185 in shutdown
Windows fatal exception: code 0x80010108

Thread 0x00005e8c (most recent call first):
  File "C:\Users\Yujin\AppData\Roaming\Python\Python38\site-packages\comtypes\__init__.py", line 185 in shutdown

Specifications

  • pywin32 version: 227
  • comtypes version: 1.1.7
  • Pytest version: 5.3.1
  • Pywinauto version: 0.6.8
  • Python version and bitness: 3.8 (64 bit) (also tried 3.6, 3.7)
  • Platform and OS: Win10 x64

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:20 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Fobos23commented, Dec 20, 2021

I started pytest with -p no:faulthandler and it helped me. Look at this for more information.

1reaction
KyleKingcommented, Jan 23, 2020

Ok, so this is the minimum code to reproduce the error:

import comtypes
import comtypes.client

UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
ui_automation_client = comtypes.gen.UIAutomationClient
iuia = comtypes.CoCreateInstance(
    ui_automation_client.CUIAutomation().IPersist_GetClassID(),
    interface=ui_automation_client.IUIAutomation,
    clsctx=comtypes.CLSCTX_INPROC_SERVER,
).GetRootElement()


def test_case():
    assert True

This above snippet is modified from the below pywinauto code:

https://github.com/pywinauto/pywinauto/blob/4005bff2aacb6e5421a43abdbdd2f4c178ca53b4/pywinauto/windows/uia_defines.py#L43-L64

I’m a little out of my depth here. From what I can piece together, this only occurs when I call the above snippet (the simplified code from pywinauto–no need to import pywinauto) and use pytest. Calling the snippet with Python doesn’t throw the fatal exception.

I can’t locate what calls the shutdown() method from comtypes that is reporting the Fatal exception on couninitialize. I tried to call the snippet with multiprocess, but I haven’t been able to create an example without pytest

What do you think? What could I try for next steps?

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest - Windows fatal exception: code 0x8001010d
When I run the code normally, it does not complain. However, when I am doing it via pytest, it throws a bunch of...
Read more >
UI crashes because of Windows fatal exception - Joulescope
I was recently trying to open the Joulescope UI from the command-line like this: >"C:\Program Files (x86)\Joulescope\joulescope.exe" ...
Read more >
Issues · pywinauto/pywinauto · GitHub
Desktop(backend='uia').windows() returns [] after running the script once need ... [pytest integration] (Windows fatal exception: code 0x80010108) ...
Read more >
Windows fatal exception: access violation - Python Forum
Windows fatal exception : access violation ... import pytest ... I just wonder how that fatal exception occurs and how we can fix...
Read more >
Getting Error As Pywinauto.Application.Processnotfounderror
If you use Maven you can use the following code to add the dependency for ... [pytest integration] Windows fatal exception: code 0x80010108...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found