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.

3
  • Possible duplicate of create a pyqt build in GitLab Commented Mar 10, 2018 at 6:58
  • Alternatively, consider using QCoreApplication when running the unit tests. Commented Mar 10, 2018 at 6: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) Commented Mar 10, 2018 at 12:49

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried to modify sys.argv for QApplication, tried xvfb. nothing worked except this. You saved my day!. Thanks.
This is exactly what you need to run PyQt5 tests on GitlabCI. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.