使用 QT 运行 pytest 时出现致命的 Python 错误 [英] Fatal Python Error when running pytest with QT

查看:57
本文介绍了使用 QT 运行 pytest 时出现致命的 Python 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 pytest 的新手,在尝试运行我的测试文件之一时遇到问题.我得到以下输出:

I'm new to pytest and I'm having trouble trying to run one of my test files. I'm getting the following output:

================================================== test session starts ==================================================
platform linux -- Python 3.7.6, pytest-5.3.5, py-1.8.1, pluggy-0.13.1 -- /home/jarel/anaconda3/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/jarel/workspace/spyder/rpgland/.hypothesis/examples')
PyQt5 5.9.2 -- Qt runtime 5.9.7 -- Qt compiled 5.9.6
rootdir: /home/jarel/workspace/spyder/rpgland
plugins: astropy-header-0.1.2, cov-2.8.1, openfiles-0.4.0, arraydiff-0.3, hypothesis-5.5.4, qt-3.3.0, doctestplus-0.5.0, remotedata-0.3.2
collected 1 item                                                                                                        

rpgland/test_character_window.py::test_init_character Fatal Python error: Aborted

Current thread 0x00007fb5b7229740 (most recent call first):
  File "/home/jarel/workspace/spyder/rpgland/rpgland/view/character_info_window.py", line 9 in __init__
  File "/home/jarel/workspace/spyder/rpgland/rpgland/test_character_window.py", line 20 in gui
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 788 in call_fixture_func
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 958 in pytest_fixture_setup
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 909 in execute
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 580 in _compute_fixture_value
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 499 in _get_active_fixturedef
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 483 in getfixturevalue
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 473 in _fillfixtures
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/fixtures.py", line 294 in fillfixtures
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/python.py", line 1449 in setup
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 370 in prepare
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 122 in pytest_runtest_setup
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 210 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 237 in from_call
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 210 in call_runtest_hook
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 185 in call_and_report
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 93 in runtestprotocol
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/runner.py", line 84 in pytest_runtest_protocol
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/main.py", line 271 in pytest_runtestloop
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/main.py", line 247 in _main
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/main.py", line 197 in wrap_session
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/main.py", line 240 in pytest_cmdline_main
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/callers.py", line 187 in _multicall
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 87 in <lambda>
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/manager.py", line 93 in _hookexec
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/pluggy/hooks.py", line 286 in __call__
  File "/home/jarel/anaconda3/lib/python3.7/site-packages/_pytest/config/__init__.py", line 93 in main
  File "/home/jarel/anaconda3/bin/pytest", line 11 in <module>
Aborted (core dumped)

它看起来令人窒息的那一行是在 character_info_window 模块中 CharacterInfowWindow 类(QtWidgets.QMainWindow 的子类)的 __init__() 函数中调用super".关于可能是什么问题的任何想法?

The line it looks to be choking on is a call to "super" within the __init__() function of the CharacterInfowWindow class (subclass of QtWidgets.QMainWindow) within the character_info_window module. Any ideas on what could be the problem?

推荐答案

我今天也遇到了这个问题.我的解决方案是在我的测试目录中创建一个 pytest.ini 文件并将其包含在其中.

I had this issue today as well. The solution for me was to create a pytest.ini file in my tests directory and include this in it.

[pytest]
qt_api=pyqt5

来自 https://github.com/pytest-dev/pytest-qt

要强制使用特定的 API,请将 pytest.ini 文件中的配置变量 qt_api 设置为 pyqt5 或 pyside2

To force a particular API, set the configuration variable qt_api in your pytest.ini file to pyqt5 or pyside2

在 pytest.ini 中设置 qt_api 后,测试运行没有任何问题

Once I set the qt_api in the pytest.ini the tests ran without any issues

这篇关于使用 QT 运行 pytest 时出现致命的 Python 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆