Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Docker Qt6 xcb issue running pytest
QtWS25 Last Chance

Docker Qt6 xcb issue running pytest

Scheduled Pinned Locked Moved Solved QtWebEngine
pyside6docker
2 Posts 1 Posters 766 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AdamG
    wrote on last edited by AdamG
    #1

    I have the following Dockerfile

    # Use the official Python base image
    FROM python:3.11-bullseye
    
    RUN pip install numpy && pip install setuptools
    
    # Copy the debPackages.txt file
    COPY debPackages.txt .
    
    # Install Qt6 dependencies
    RUN apt-get update && apt-get install $(grep -vE "^\s*#" debPackages.txt  | tr "\n" " ") -y
    
    # Set the working directory in the container
    WORKDIR /app
    
    # Copy the requirements.txt file
    COPY requirements.txt .
    
    # Upgrade pip
    RUN pip install --upgrade pip
    
    # Install the Python dependencies
    RUN pip install --no-cache-dir -r requirements.txt
    
    # Copy the project files
    COPY . .
    
    
    
    # Copy the test files
    # COPY ./tests ./tests
    
    ENV PYTHONDONTWRITEBYTECODE=true
    ENV QT_DEBUG_PLUGINS=1
    # ENV QTPLUGIN.platforms += qoffscreen
    ENV DISPLAY=:0.0
    ENV QT_QPA_PLATFORM=offscreen
    ENV QT_DEBUG_PLUGINS=1
    # ENV QT_QPA_PLATFORM=xcb
    ENV QT_QPA_PLATFORM_PLUGIN_PATH=/opt/Qt/${QT_VERSION}/gcc_64/plugins
    ENV QT_PLUGIN_PATH=/opt/Qt/${QT_VERSION}/gcc_64/plugins
    ENV DISPLAY=:1
    ENV PYTHONPATH "${PYTHONPATH}:/app"
    
    RUN pip install .
    
    # Expose the port the application runs on
    EXPOSE 8000
    
    CMD ["coverage", "run", "-m", "pytest"]
    

    and have been getting the following error running my docker container:

    qt.core.plugin.factoryloader: Got keys from plugin meta data QList("gtk3")
    qt.core.plugin.factoryloader: checking directory path "/usr/local/bin/platformthemes" ...
    qt.core.plugin.factoryloader: checking directory path "/opt/Qt//gcc_64/plugins" ...
    qt.core.plugin.factoryloader: checking directory path "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/styles" ...
    qt.core.plugin.factoryloader: checking directory path "/usr/local/bin/styles" ...
    Qt WebEngine seems to be initialized from a plugin. Please set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute and QSGRendererInterface::OpenGLRhi using QQuickWindow::setGraphicsApi before constructing QGuiApplication.
    qt.core.plugin.factoryloader: checking directory path "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/accessiblebridge" ...
    qt.core.plugin.factoryloader: checking directory path "/usr/local/bin/accessiblebridge" ...
    WebEngineContext is used before QtWebEngineQuick::initialize() or OpenGL context creation failed.
    [1:1:0922/220421.558779:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
    "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so" unloaded library 
    make: *** [Makefile:27: test] Error 1
    

    If I take out RUN pip install ., the error won't show up, but the unit tests fail because they can't find the project build. If I replace offscreen with xcb then I get a different error. I've researched this extensively but can't find an answer.

    Thank you for any help you can provide.

    EDIT:

    I just discovered it is an issue specifically with one unit test file in particular. The test is

    import pytest
    from PySide6.QtWidgets import QApplication
    from sys import argv
    import sys
    from PySide6.QtCore import QUrl
    
    class TestMerlotBrowser:
        @pytest.fixture(autouse=True)
        def setup_method(self, mocker):
            if not QApplication.instance():
                testApp = QApplication(argv)
            else:
                testApp = QApplication.instance()
    
            with mocker.patch("backend.merlotLogger") as mockLogger, mocker.patch("sql.merlotDB") as mockDB, mocker.patch("backend.persistantProcs") as mockProcs, mocker.patch("attributes.menu") as mockMenu, mocker.patch("PySide6.QtWidgets.QMainWindow.setMenuBar") as mockSetMenuBar:
                from merlot.merlot import Browser
                self.brows = Browser()
    
        def testBrowser(self):
            assert self.brows.procs.runProcs.call_count == 1
            
        def test_go_to_URL(self):
            testURL = QUrl("www.duckduckgo.com")
            self.brows.go_to_URL(testURL)
            self.brows.db.insertRecord.assert_called_with("https:www.duckduckgo.com")
    

    where Browser is a class Browser(QMainWindow): object. If I remove this test file, the other unit tests run perfectly fine.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AdamG
      wrote on last edited by
      #2

      It turned out the error I needed to research specifically was ERROR:zygote_host_impl_linux.cc(100). I found a solution here:

      https://stackoverflow.com/questions/62284578/docker-errorzygote-host-impl-linux-cc89-running-as-root-without-no-sandb

      And the new Dockerfile is

      # Use the official Python base image
      FROM python:3.11-bullseye
      
      RUN pip install numpy && pip install setuptools
      
      # Copy the debPackages.txt file
      COPY debPackages.txt .
      
      # Install Qt6 dependencies
      RUN apt-get update && apt-get install $(grep -vE "^\s*#" debPackages.txt  | tr "\n" " ") -y
      
      # Set the working directory in the container
      WORKDIR /app
      
      # Copy the requirements.txt file
      COPY requirements.txt .
      
      # Upgrade pip
      RUN pip install --upgrade pip
      
      # Install the Python dependencies
      RUN pip install --no-cache-dir -r requirements.txt
      
      # Copy the project files
      COPY . .
      
      
      ENV PYTHONDONTWRITEBYTECODE=true
      
      # Export QT specific settings
      ENV QT_DEBUG_PLUGINS=1
      ENV QT_QPA_PLATFORM=offscreen
      ENV QTWEBENGINE_DISABLE_SANDBOX=1
      
      
      RUN pip install .
      
      # Expose the port the application runs on
      EXPOSE 8000
      
      CMD ["coverage", "run", "-m", "pytest"]
      

      so adding ENV QTWEBENGINE_DISABLE_SANDBOX=1 fixed everything.

      1 Reply Last reply
      0
      • A AdamG has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved