致力于了解如何对基于 PySide2 的应用程序进行自动化单元测试。但是,每当我尝试QApplication
在测试中初始化实例时,无论是通过PySide2
自身还是通过pytest-qt
qtbot 夹具,travis-ci 都会中止测试。但是,它在本地工作。
我尝试使用qtbot
和中的qapp
固定装置pytest-qt
,尝试不同的travis-ci
发行版,例如xenial
and trusty
,以及包括pytest-xvfb
我看到的类似 stackoverflow 问题的答案所推荐的插件,但在上述任何组合中都没有任何效果。
# .travis.yml
language: python
python:
- "3.6"
cache: pip
dist: xenial
install: pip install -r requirements.txt
# running from top folder level to keep package on the path
script: python -m pytest tests/
# tests/test_central.py
from lysiaa.central import MyWindow
def test_giveBack(qapp):
window = MyWindow()
assert window.giveBack(1) == 1
# lysiaa/central.py
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
def giveBack(self, param):
return param
但是,当travis-ci
尝试运行它时,它会因核心转储而中止。有人可以帮我解决这个问题吗?
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.5.0, py-1.8.0, pluggy-0.11.0
PySide2 5.12.3 -- Qt runtime 5.12.3 -- Qt compiled 5.12.3
rootdir: /home/travis/build/robert-clayton/LYSIAA
plugins: xvfb-1.2.0, qt-3.2.2
collected 1 item
tests/test_central.py /home/travis/.travis/functions: line 104: 4092 Aborted (core dumped) python -m pytest tests/
The command "python -m pytest tests/" exited with 134.