- Package:
- python3-pytestqt
- Source:
- python3-pytestqt
- Submitter:
- VA
- Date:
- 2026-02-06 08:43:02 UTC
- Severity:
- normal
I have python3-pytestqt for testing some PyQt programs (also it's a
dependency of some debian packages).
However, merely installing pyside (because it's a dependency of some
debian packages) breaks *ALL* pytest uses as long as python3-pytestqt is
installed:
```
% cat test.py
def test_foo(): pass
% python3 -Is -m pytest test.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/lib/python3/dist-packages/_pytest/main.py",
line 314, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^
INTERNALERROR> File
"/usr/lib/python3/dist-packages/_pytest/config/__init__.py", line 1159,
in _do_configure
INTERNALERROR>
self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/lib/python3/dist-packages/pluggy/_hooks.py",
line 534, in call_historic
INTERNALERROR> res = self._hookexec(self.name,
self._hookimpls.copy(), kwargs, False)
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods,
kwargs, firstresult)
INTERNALERROR>
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pluggy/_callers.py", line 167, in _multicall
INTERNALERROR> raise exception
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pluggy/_callers.py", line 121, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pytestqt/plugin.py", line 243, in
pytest_configure
INTERNALERROR> qt_api.set_qt_api(config.getini("qt_api"))
INTERNALERROR> ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pytestqt/qt_compat.py", line 110, in
set_qt_api
INTERNALERROR> self.QtTest = _import_module("QtTest")
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^
INTERNALERROR> File
"/usr/lib/python3/dist-packages/pytestqt/qt_compat.py", line 106, in
_import_module
INTERNALERROR> return getattr(m, module_name)
INTERNALERROR> File
"/usr/lib/python3/dist-packages/PySide6/__init__.py", line 127, in
__getattr__
INTERNALERROR> raise AttributeError(f"module '{__name__}' has no
attribute '{name}' :)")
INTERNALERROR> AttributeError: module 'PySide6' has no attribute 'QtTest' :)
```
I'm running debian's stock python in isolated mode (so no virtual env,
no PYTHONPATH, no user libs, only stuff from debian packages), and a
test not even using qt/pyqt/pyside simply cannot run.
It seems by default all pytest plugins are run, and the pyside package
hijacks something that the pytestqt plugin expects.
Please make pyside be a good citizen and not intercept pyqt imports.
Control: reassign -1 python3-pytestqt It doesn't break *ALL*, but it will certainly break anything that requires PyQt5, PyQt6 or PySide2 and has not declared that. That's because pytestqt tries to do some autodetection of which Python Qt API to use and this detection is somewhere between fragile and buggy. No hijacking involved, just that the tests you are running have not specified which Qt API they should be run against (they should, see the pytestqt docs [1]), and the pytestqt detection of the Python Qt API is flawed. [1] https://pytest-qt.readthedocs.io/en/latest/intro.html#requirements There is absolutely nothing that PySide6 packaging can do about this. regards Stuart
Le 05/02/2026 à 13:03, Stuart Prescott a écrit : I insist, all pytest usage breaks: as you can (re-)read in my previous message, the test file doesn't use any import at all, just: def test_foo(): pass in a file and pytest breaks.
Hi again
$ echo "def test_foo(): pass" > test_foo.py
$ pytest
============================================== test session starts
==============================================
platform linux -- Python 3.13.11, pytest-8.4.2, pluggy-1.6.0
PySide6 6.9.2 -- Qt runtime 6.9.2 -- Qt compiled 6.9.2
rootdir: /tmp/pkgs
plugins: anyio-4.11.0, typeguard-4.4.4, qt-4.4.0, cov-5.0.0, zarr-3.1.5,
hypothesis-6.151.4, mock-3.15.1, syrupy-5.0.0, subtests-0.15.0
collected 1 item
test_foo.py .
[100%]
=============================================== 1 passed in 0.09s
===============================================
As I said in my initial reply, this is due to pytestqt's somewhat
imperfect Qt API detection and it is there that you need to look for a
solution.
The pytestqt docs I linked to offer the following options as workarounds
for you right now:
- tell pytestqt to use an API other than PySide6, e.g. by setting
PYTEST_QT_API=pyqt5
- tell pytest not to load plugins by setting
PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
or alternatively you could, as a workaround:
- install the python3-pyside6.qttest package as well
- uninstall the python3-pytestqt package (nothing in Debian requires
it at runtime)
The longer term fix to pytestqt is likely what Rebecca Palmer noted in
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1125222#24
Stuart
Le 05/02/2026 à 23:38, Stuart Prescott a écrit : > $ echo "def test_foo(): pass" > test_foo.py > $ pytest > ============================================== test session starts > ============================================== > platform linux -- Python 3.13.11, pytest-8.4.2, pluggy-1.6.0 > PySide6 6.9.2 -- Qt runtime 6.9.2 -- Qt compiled 6.9.2 > rootdir: /tmp/pkgs > plugins: anyio-4.11.0, typeguard-4.4.4, qt-4.4.0, cov-5.0.0, zarr-3.1.5, > hypothesis-6.151.4, mock-3.15.1, syrupy-5.0.0, subtests-0.15.0 > collected 1 item > > test_foo.py . [100%] > > =============================================== 1 passed in 0.09s > =============================================== Then your setup is cooked. Try with a fresh setup: ``` docker run --rm -i docker.io/debian:stable << EOF apt-get update apt-get install -y --no-install-recommends python3-pytest \ python3-pyside6.qtcore python3-pytestqt echo "def test_foo(): pass" > test.py pytest test.py EOF […] INTERNALERROR> AttributeError: module 'PySide6' has no attribute 'QtGui' :) ``` I can hardly make it more reproducible for you than this. > As I said in my initial reply, this is due to pytestqt's somewhat > imperfect Qt API detection and it is there that you need to look for a > solution. > > The pytestqt docs I linked to offer the following options as workarounds > for you right now: > > - tell pytestqt to use an API other than PySide6, e.g. by setting > PYTEST_QT_API=pyqt5 > - tell pytest not to load plugins by setting > PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 > > or alternatively you could, as a workaround: > > - install the python3-pyside6.qttest package as well > - uninstall the python3-pytestqt package (nothing in Debian requires > it at runtime) > > The longer term fix to pytestqt is likely what Rebecca Palmer noted in > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1125222#24 Should we reopen that bug?
Hi No, nothing is cooked about my setup. Leaving out the on-going insults each time I try to help you would also be appreciated, thanks. You will find that many quite standard setups will not suffer from this at all - anyone testing against PySide6 (which at this stage is probably most people installing pytestqt), for example. I did not ask for a reproducer, it's trivially reproducible and I've already indicated that I know the underlying cause - that's how I verified the multiple workarounds I gave you. Twice. No need, that bug is about fixing the dependencies of python3-pytestqt and that has been done. This bug is already filed against python3-pytestqt and has a pointer to the likely fix.