3

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

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: Could not connect to display bash: line 62: 50549 Aborted (core dumped) python3 -m unittest -v test ERROR: Job failed: exit status 1

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)

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.

Thanks a lot.

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

  • Possible duplicate of [create a pyqt build in GitLab](https://stackoverflow.com/questions/37662616/create-a-pyqt-build-in-gitlab) – three_pineapples Mar 10 '18 at 06:58
  • Alternatively, consider using `QCoreApplication` when running the unit tests. – three_pineapples Mar 10 '18 at 06:59
  • Thank you @three_pineapples! I have added the following lines to my test.py file but still getting the same error. Have I misunderstood anything? sys.path.insert(0, "../") sys.argv = ['-platform', 'minimal'] from src import gui application = QApplication(sys.argv) – Nikiforos Botis Mar 10 '18 at 12:49

1 Answers1

6

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
Steve
  • 61
  • 1
  • 3