Windows fatal exception with pytest + pythonnet
See original GitHub issueEnvironment
- 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.
- What commands did you run to trigger this issue? If you can provide a Minimal, Complete, and Verifiable example this will help us understand the issue.
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:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@lostmsu : thanks! You are right, this is not related to Python.NET:
faulthandler
module is automatically enabled for pytest runs: https://docs.pytest.org/en/latest/how-to/failures.html#fault-handler@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 ownfaulthandler
, that dumps exception, that is later handled in a normal way.Again, I do not see how this is related to Python.NET