pytest-qt
pytest support for PyQt and PySide applications
What it is and what it does
pytest-qt bridges pytest and Qt application testing by providing the qtbot fixture, which manages Qt application lifecycle and exposes methods to simulate user interactions like mouse clicks and key presses. It also captures Qt debug/warning/critical messages automatically and provides waitSignal/waitSignals functions to block tests until specific signals are emitted, plus automatic exception handling in virtual methods and slots.
The plugin auto-detects which Qt library (PySide6, PyQt6, or PyQt5) is available or already imported, or lets you force a choice via pytest.ini or environment variable. It's designed for developers who need to verify that the view layer of a Qt application behaves correctly after code changes, without requiring manual GUI interaction.
Use it for:
- Test button clicks and user input on PyQt5/PyQt6/PySide6 widgets to verify UI state changes.
- Verify that Qt signals are emitted at the right time using waitSignal/waitSignals in your test suite.
- Capture and assert on qDebug, qWarning, and qCritical messages emitted during widget operations.
- Validate exception handling in Qt virtual methods and slots by letting pytest-qt catch and report them.
- Automate GUI regression testing in CI pipelines by simulating user interactions programmatically.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pytest-qt is a pytest plugin that provides fixtures and utilities to test PyQt5, PyQt6, and PySide6 applications, including widget interaction simulation and signal handling.
Yes. pytest-qt is production-stable (since 2013), actively maintained, has no known vulnerabilities, and installs with low friction. Install it if you're testing PyQt or PySide applications and want pytest-native fixtures for widget interaction and signal handling. The only prerequisite is having one of PyQt5, PyQt6, or PySide6 already available.
Install
pytest-qt on PyPI
pip
pip install pytest-qtuv
uv add pytest-qtpoetry
poetry add pytest-qtInstalling pytest-qt
Before you install
Low friction install with stable maintenance: the package is actively maintained (last commit 2026-08-03), has been in production since 2013, and depends only on pytest, pluggy, and typing_extensions—all widely available.
License in practice
MIT license is permissive; you can use this package in commercial or proprietary projects with minimal restrictions, provided you include the license notice.
Quickstart
pip install pytest-qt
# In your test file:
def test_widget(qtbot):
widget = MyWidget()
qtbot.addWidget(widget)
qtbot.mouseClick(widget.button, qt_api.QtCore.Qt.MouseButton.LeftButton)
Requires PyQt5, PyQt6, or PySide6 to be installed separately; pytest-qt will auto-detect or you can set qt_api in pytest.ini or PYTEST_QT_API environment variable.
Verify before relying
- Whether the package handles headless/CI environments without additional configuration beyond pytest-xvfb.
- Performance characteristics when testing large widget hierarchies or many signals.
- Compatibility guarantees across PyQt5/PyQt6/PySide6 API differences in test code.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — pytest, pluggy, typing_extensions |
| Maintenance | actively maintained — 409 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,187,026/month — #4,247 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_qt-4.5.0-py3-none-any.whl
Keywords: pytest, qt, test, unittest
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-seleniumpytest-selenium is a pytest plugin that…
copyleft · top 15,000 on PyPI
QtPyQtPy provides a unified API for writing Qt…
permissive · top 5,000 on PyPI
pyqt5-toolsProvides Qt Designer, QML Scene, and QML Test…
copyleft · top 15,000 on PyPI
pytest-rabbitmqA pytest plugin that provides fixtures to start…
copyleft · top 15,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
pytest-aiohttpPytest plugin that provides fixtures for…
permissive · top 5,000 on PyPI
tdd-guard-pytestA pytest plugin that captures test results and…
permissive · top 15,000 on PyPI
qtconsoleQtConsole is a Qt-based graphical console for…
permissive · top 5,000 on PyPI
pytest-djangopytest-django integrates Django with pytest,…
permissive · top 1,000 on PyPI