ui自动化测试数据复原遇到的坑——2、python连接informix时pytest报致命错误Windows fatal exception: access violation

2022-12-25,,,,

python连接informix只能通过jdbc(需要先部署java环境。我试过到IBM上下载ODBC但结局是失败的),在执行pytest时发现有一串报错(大致是下面的这样):

Windows fatal exception: access violation
Current thread 0x00000864 (most recent call first):
  File "C:\Miniconda36-x64\lib\site-packages\jpype\_core.py", line 227 in startJVM
File "C:\projects\ixmp\tests\backend\test_jdbc.py", line 18 in test_gh_229
File "C:\Miniconda36-x64\lib\site-packages\_pytest\python.py", line 166 in pytest_pyfunc_call
File "C:\Miniconda36-x64\lib\site-packages\pluggy\callers.py", line 187 in _multicall
File "C:\Miniconda36-x64\lib\site-packages\pluggy\manager.py", line 81 in <lambda>

但整个项目可以正常执行,因影响到了最终allure的测试报告显示的成功率,主管让我想办法。我首先在自己的demo项目中用同样的方法连接informix,并没有报错。所以想到是pytest的问题?但

在百度、csdn、bing、StackOverflow查找无果后,我终于在github上的jpype(python调用java的包)项目的issue找到解决方法:https://github.com/jpype-project/jpype/issues/561

提问人与作者讨论了挺多内容,最后发现是jvm启动时会触发异常,以检查其挂钩是否已安装(The first thing that it does when starting up the JVM is triggering an exception to check if the hook is installed)

而pytest安装了自己的挂钩干预了java的挂钩(But it appears possible that pytest installs its own hooks which interfere with the Java hooks)

所以pytest捕获到这个异常,并打印出来了。

解决方法:在pytest.ini的addopts添加-p no:faulthandler,以禁用这种故障处理

官方文档:https://docs.pytest.org/en/latest/usage.html#fault-handler

ui自动化测试数据复原遇到的坑——2、python连接informix时pytest报致命错误Windows fatal exception: access violation的相关教程结束。

《ui自动化测试数据复原遇到的坑——2、python连接informix时pytest报致命错误Windows fatal exception: access violation.doc》

下载本文的Word格式文档,以方便收藏与打印。