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.

Windows fatal exception with pytest + pythonnet

See original GitHub issue

Environment

  • Pythonnet version: 2.5.2
  • Python version: Python 3.8.11 :: Anaconda, Inc. on win32
  • Operating System: Windows Server 2019 Datacenter 10.0.17763
  • .NET Runtime: 4.7.03190

Details

  • Describe what you were trying to get done.

We are using pythonnet to interact with the C# API of a 3rd party proprietary software. Everything works fine, but when we upgraded pytest from version 4.6.11 to 5.x or 6.x we started to see Windows fatal exceptions when executing some of the tests.

The tests themselves are not failing, but we were wondering if anyone else had the same issue with “newer” versions of pytest and if there is any hint about why the exception is thrown (and how we can further investigate).

The issue seems to be similar to https://github.com/pythonnet/pythonnet/issues/1011 , but in our case we are never using clr.AddReference with explicit paths.

pytest -v mcea_ma_engine\tests\test_swap_ct_api.py::test_calibration

It is difficult to provide a MCVE because the behavior is triggered when calling a method (“LoadXML”) coming from a 3rd party assembly for which unfortunately we don’t have access to the sources.

The Python code looks more or less like this (the last line triggers the fatal exception):

clr.AddReference("x.y.z.API")
import x.y.z.API.Swaptions as SW
ct = SW.SwaptionTool().LoadXML("file.xml")
  • If there was a crash, please include the traceback here.
$ pytest -v mcea_ma_engine\tests\test_swap_ct_api.py::test_calibration

================================================= test session starts =================================================
platform win32 -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\NICOLA.LAMBIASE\Documents\mcea-ma-engine, configfile: setup.cfg
plugins: cov-2.11.1
collected 1 item

mcea_ma_engine/tests/test_swap_ct_api.py::test_calibration Windows fatal exception: code 0xe0564552

Current thread 0x00003c34 (most recent call first):
  File "C:\Users\NICOLA.LAMBIASE\Documents\mcea-ma-engine\mcea_ma_engine\api\swaption_ct.py", line 45 in __init__
  File "C:\Users\NICOLA.LAMBIASE\Documents\mcea-ma-engine\mcea_ma_engine\tests\test_swap_ct_api.py", line 32 in test_swaption_tool
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 932 in call_fixture_func
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 1126 in pytest_fixture_setup
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\callers.py", line 187 in _multicall
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 84 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 93 in _hookexec
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\hooks.py", line 286 in __call__
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 1072 in execute
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 687 in _compute_fixture_value
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 601 in _get_active_fixturedef
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 581 in getfixturevalue
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\fixtures.py", line 568 in _fillfixtures
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\python.py", line 1647 in setup
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 449 in prepare
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 150 in pytest_runtest_setup
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\callers.py", line 187 in _multicall
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 84 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 93 in _hookexec
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\hooks.py", line 286 in __call__
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 255 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 311 in from_call
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 254 in call_runtest_hook
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 215 in call_and_report
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 120 in runtestprotocol
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\runner.py", line 109 in pytest_runtest_protocol
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\callers.py", line 187 in _multicall
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 84 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 93 in _hookexec
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\hooks.py", line 286 in __call__
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\main.py", line 348 in pytest_runtestloop
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\callers.py", line 187 in _multicall
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 84 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 93 in _hookexec
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\hooks.py", line 286 in __call__
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\main.py", line 323 in _main
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\main.py", line 269 in wrap_session
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\main.py", line 316 in pytest_cmdline_main
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\callers.py", line 187 in _multicall
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 84 in <lambda>
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\manager.py", line 93 in _hookexec
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\pluggy\hooks.py", line 286 in __call__
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\config\__init__.py", line 162 in main
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\lib\site-packages\_pytest\config\__init__.py", line 185 in console_main
  File "C:\Users\NICOLA.LAMBIASE\.conda\envs\mcea-ma-engine-3.8\Scripts\pytest-script.py", line 10 in <module>
PASSED                                                [100%]

================================================== 1 passed in 5.82s ==================================================

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lambiasecommented, Sep 23, 2021

@lostmsu : thanks! You are right, this is not related to Python.NET:

0reactions
lostmsucommented, Sep 22, 2021

@lambiase considering the call goes as normal, your issue is probably deeper: https://bugs.python.org/issue31701

It is possible the new pytest simply adds its own faulthandler, that dumps exception, that is later handled in a normal way.

Again, I do not see how this is related to Python.NET

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytest - Windows fatal exception: code 0x8001010d
I am trying to run a GUI test using pytest and pywinauto. When I run the code normally, it does not complain. However,...
Read more >
Windows fatal exception: access violation - Python discussion
If an OS exception isn't handled at a low level by the interpreter or an extension module, the process crashes hard.
Read more >
[Fixed] Fatal Python Error: Unable to Load the File System ...
1. Search for “edit the system environment variables” in Windows Search and open the matched result. · 2. In the new popup named...
Read more >
Pytest fails with access violation?
I'm building a project in python with the Orekit python wrapper, ... Windows fatal exception: access violation Current thread 0x00002e10 ...
Read more >
pyjion
Pyjion, a JIT extension for CPython that compiles your Python code into native CIL and executes it using the .NET 7 CLR. Documentation...
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