使用Gitlab的CI在PyQt5中自动化单元测试:QXcbConnection错误 [英] Automating unit testing in PyQt5 using Gitlab's CI: QXcbConnection error

查看:100
本文介绍了使用Gitlab的CI在PyQt5中自动化单元测试:QXcbConnection错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在使用PyQt5创建一个GUI框架,并且已经编写了一些单元测试(使用Python的unittest包)以测试其基本功能。尝试在每次对此存储库(当前托管在GitLab中)进行提交时使运行这些单元测试的过程自动化时,我创建了以下 .gitlab-ci.yml 文件:

I am creating a GUI skeleton (for now) using PyQt5 and I have written some unit tests (using Python's unittest package) for testing its basic features. While trying to automate the procedure of running those unit tests each time a commit is made to this repository (currently hosted in GitLab), I have created the following .gitlab-ci.yml file:

before_script:
 - sudo apt-get -qq update && sudo apt-get -qq install -y python3
 - sudo apt-get -qq update
 - sudo apt-get -qq install -y python3 python-virtualenv python3-pip 
 - virtualenv venv
 - . venv/bin/activate
 - sudo apt-get install python3-pyqt5 -y
 - sudo apt-get install python3-pyqt5.qtmultimedia -y
 - cd test

stages: 
    - test

job1:
    stage: test
    script: python3 -m unittest -v test.GuiTest

确实运行(所以应该正确设置跑步者),但是执行以下脚本时出现以下错误作业1

Which does run (so the runners should have been set up correctly) but I am getting the following error when executing the script of job 1:


$ python3 -m unittest -v test
QXcbConnection:无法连接以显示
bash:行62:50549中止(核心转储)python3 -m unittest -v test
错误:作业失败:退出状态1

$ python3 -m unittest -v test QXcbConnection: Could not connect to display bash: line 62: 50549 Aborted (core dumped) python3 -m unittest -v test ERROR: Job failed: exit status 1

根据我所做的研究,CI服务器似乎在尝试运行图形应用程序时遇到问题。但是,对于运行单元测试,不需要打开任何实际窗口。问题似乎是测试(.py)文件的这一行:

From the research I did, it seems that the CI server is facing problems trying to run a graphical application. However, for running the unit tests, no any actual window needs to be opened. The problem seems to be this particular line of the test (.py) file:


application = QApplication(sys.argv)

application = QApplication(sys.argv)

有什么方法可以绕过此问题?我确实知道,如果测试功能需要任何图形功能(例如,按下按钮),这将是一个问题,但是在这种情况下,则没有这种需要。

Is there any way in which I can bypass this issue? I do understand that if the testing functions required any graphical feature (e.g. pressing a button) this would be a problem but in this case, there is no such need.

谢谢

编辑:请问一下这个问题,因为它的发布时间可能不正确。

EDIT: Could you please have a look at this question since it was probably posted on an incorrect timing.

推荐答案

您可以尝试通过在.yml文件中设置环境变量QT_QPA_PLATFORM将Qt使用的后端设置为屏幕外。

You can try setting the backend used by Qt to "offscreen" by setting the env var QT_QPA_PLATFORM in your .yml file.

job1:
    stage: test
    variables:
      QT_QPA_PLATFORM: "offscreen"
    script: python3 -m unittest -v test.GuiTest

这篇关于使用Gitlab的CI在PyQt5中自动化单元测试:QXcbConnection错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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