Fatal Python error: Aborted
Asked by Captain Haddock:

For my pipeline I have a single test file (test_xxxx.py) that contains many cases. Using the same command as I have configured in my bitbucket-pipelines.yml, I am able to run the tests on my local Ubuntu machine (22.04) yet when run on a BitBucket pipeline VM I see the following:  

    ============================= test session starts ==============================

    platform linux -- Python 3.7.16, pytest-7.2.1, pluggy-1.0.0 -- /usr/local/bin/python

    cachedir: .pytest_cache

    PyQt5 5.15.8 -- Qt runtime 5.15.2 -- Qt compiled 5.15.2

    rootdir: /opt/atlassian/pipelines/agent/build, configfile: https://bitbucket.org/insightsurgicaltechnologies/qfprobe/src/f3d14ec15ce2f00ed8cd309a79dbf2ab2802e4f0/pytest.ini

    plugins: qt-4.2.0, mock-3.10.0

    collecting ... collected 9 items

    Fatal Python error: Aborted

    Current thread 0x00007f7192ad3740 (most recent call first):

      File "/usr/local/lib/python3.7/site-packages/pytestqt/plugin.py", line 66 in qapp

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 908 in call_fixture_func

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 1129 in pytest_fixture_setup

      File "/usr/local/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall

      File "/usr/local/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec

      File "/usr/local/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 1075 in execute

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 677 in _compute_fixture_value

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 591 in _get_active_fixturedef

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 569 in getfixturevalue

      File "/usr/local/lib/python3.7/site-packages/_pytest/fixtures.py", line 550 in _fillfixtures

      File "/usr/local/lib/python3.7/site-packages/_pytest/python.py", line 1792 in setup

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 492 in setup

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 155 in pytest_runtest_setup

      File "/usr/local/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall

      File "/usr/local/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec

      File "/usr/local/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 260 in <lambda>

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 339 in from_call

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 260 in call_runtest_hook

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 220 in call_and_report

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 125 in runtestprotocol

      File "/usr/local/lib/python3.7/site-packages/_pytest/runner.py", line 112 in pytest_runtest_protocol

      File "/usr/local/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall

      File "/usr/local/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec

      File "/usr/local/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__

      File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 349 in pytest_runtestloop

      File "/usr/local/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall

      File "/usr/local/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec

      File "/usr/local/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__

      File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 324 in _main

      File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 270 in wrap_session

      File "/usr/local/lib/python3.7/site-packages/_pytest/main.py", line 317 in pytest_cmdline_main

      File "/usr/local/lib/python3.7/site-packages/pluggy/_callers.py", line 39 in _multicall

      File "/usr/local/lib/python3.7/site-packages/pluggy/_manager.py", line 80 in _hookexec

      File "/usr/local/lib/python3.7/site-packages/pluggy/_hooks.py", line 265 in __call__

      File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 168 in main

      File "/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py", line 190 in console_main

      File "/usr/local/lib/python3.7/site-packages/pytest/__main__.py", line 5 in <module>

      File "/usr/local/lib/python3.7/runpy.py", line 85 in _run_code

      File "/usr/local/lib/python3.7/runpy.py", line 193 in _run_module_as_main

    2023-02-08T01:37:52.423888867Z stdout P tests/test_qfprobe.py::test_successStates 

I assume this means there is something different about the BitBucket pipeline VM environment. Can someone suggest what might be different that could cause this problem?

I have specifically checked I am matching the versions (as seen at the start of the above trace).

From a web search I came across the following which is similar but on older versions, but I'm unsure how to apply within my BitBucket env. <https://stackoverflow.com/questions/64959516/why-a-fatal-python-error-when-testing-using-pytest-qt>  

Any thoughts welcome .. thank you


Answers:
author: Captain Haddock
body: RESOLVED: The issue was due to the lack of a display in the BitBucket CI pipeline. I solved by using xvfb thus:  

script:  
- apt-get update  
- apt-get install software-properties-common -y  
- add-apt-repository ppa:deadsnakes/ppa  
- apt install python3.7 -y  
- apt install python3-pip -y  
- if \[ -f requirements.txt \]; then pip3 install -r requirements.txt; fi  
- apt-get install xvfb -y  
- apt-get install x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps -y  
- export DISPLAY=:0;/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_0.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :0 -screen 0 1920x1200x24 -ac +extension GLX +render -noreset  
- apt-get install python3-pyqt5 -y  
- cd myproj;python3 -m pytest -v tests/\*.py;cd ..


author: Captain Haddock
body: This maybe a doh! moment.

This test that is failing is a UI test of a PyQt5-based UI desktop application. In the BitBucket pipeline there is no display. So what I'm looking for is an example PyQt5 project with pytest-qt UI tests and what the associated bitbucket-pipelines.yml might look like to run the tests.  

I have tried tinkering with xvfb with no success yet, hence reaching out to the community for those that have had success and might offer guidance.


Tags: bitbucket-cloud

cloud