pytest-qt


Namepytest-qt JSON
Version 4.4.0 PyPI version JSON
download
home_pagehttp://github.com/pytest-dev/pytest-qt
Summarypytest support for PyQt and PySide applications
upload_time2024-02-07 21:22:15
maintainer
docs_urlNone
authorBruno Oliveira
requires_python>=3.8
licenseMIT
keywords pytest qt test unittest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =========
pytest-qt
=========

pytest-qt is a `pytest`_ plugin that allows programmers to write tests
for `PyQt5`_, `PyQt6`_, `PySide2`_ and `PySide6`_ applications.

The main usage is to use the ``qtbot`` fixture, responsible for handling ``qApp``
creation as needed and provides methods to simulate user interaction,
like key presses and mouse clicks:


.. code-block:: python

    def test_hello(qtbot):
        widget = HelloWidget()
        qtbot.addWidget(widget)

        # click in the Greet button and make sure it updates the appropriate label
        qtbot.mouseClick(widget.button_greet, qt_api.QtCore.Qt.MouseButton.LeftButton)

        assert widget.greet_label.text() == "Hello!"


.. _PySide2: https://pypi.org/project/PySide2/
.. _PySide6: https://pypi.org/project/PySide6/
.. _PyQt5: https://pypi.org/project/PyQt5/
.. _PyQt6: https://pypi.org/project/PyQt6/
.. _pytest: http://pytest.org

This allows you to test and make sure your view layer is behaving the way you expect after each code change.

.. |version| image:: http://img.shields.io/pypi/v/pytest-qt.svg
  :target: https://pypi.python.org/pypi/pytest-qt

.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pytest-qt.svg
    :target: https://anaconda.org/conda-forge/pytest-qt

.. |ci| image:: https://github.com/pytest-dev/pytest-qt/workflows/test/badge.svg
  :target: https://github.com/pytest-dev/pytest-qt/actions

.. |coverage| image:: http://img.shields.io/coveralls/pytest-dev/pytest-qt.svg
  :target: https://coveralls.io/r/pytest-dev/pytest-qt

.. |docs| image:: https://readthedocs.org/projects/pytest-qt/badge/?version=latest
  :target: https://pytest-qt.readthedocs.io

.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-qt.svg
  :target: https://pypi.python.org/pypi/pytest-qt/
  :alt: Supported Python versions

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
  :target: https://github.com/ambv/black

|python| |version| |conda-forge| |ci| |coverage| |docs| |black|


Features
========

- `qtbot`_ fixture to simulate user interaction with ``Qt`` widgets.
- `Automatic capture`_ of ``qDebug``, ``qWarning`` and ``qCritical`` messages;
- waitSignal_ and waitSignals_ functions to block test execution until specific
  signals are emitted.
- `Exceptions in virtual methods and slots`_ are automatically captured and
  fail tests accordingly.

.. _qtbot: https://pytest-qt.readthedocs.io/en/latest/reference.html#module-pytestqt.qtbot
.. _Automatic capture: https://pytest-qt.readthedocs.io/en/latest/logging.html
.. _waitSignal: https://pytest-qt.readthedocs.io/en/latest/signals.html
.. _waitSignals: https://pytest-qt.readthedocs.io/en/latest/signals.html
.. _Exceptions in virtual methods and slots: https://pytest-qt.readthedocs.io/en/latest/virtual_methods.html

Requirements
============

Since version 4.1.0, ``pytest-qt`` requires Python 3.7+.

Works with either PySide6_, PySide2_, PyQt6_ or PyQt5_.

If any of the above libraries is already imported by the time the tests execute, that library will be used.

If not, pytest-qt will try to import and use the Qt APIs, in this order:

- ``PySide6``
- ``PySide2``
- ``PyQt6``
- ``PyQt5``

To force a particular API, set the configuration variable ``qt_api`` in your ``pytest.ini`` file to
``pyside6``, ``pyside2``, ``pyqt6`` or ``pyqt5``:

.. code-block:: ini

    [pytest]
    qt_api=pyqt5


Alternatively, you can set the ``PYTEST_QT_API`` environment
variable to the same values described above (the environment variable wins over the configuration
if both are set).


Documentation
=============

Full documentation and tutorial available at `Read the Docs`_.

.. _Read The Docs: https://pytest-qt.readthedocs.io

Change Log
==========

Please consult the `changelog page`_.

.. _changelog page: https://pytest-qt.readthedocs.io/en/latest/changelog.html

Bugs/Requests
=============

Please report any issues or feature requests in the `issue tracker`_.

.. _issue tracker: https://github.com/pytest-dev/pytest-qt/issues

Contributing
============

Contributions are welcome, so feel free to submit a bug or feature
request.

Pull requests are highly appreciated! If you
can, include some tests that exercise the new code or test that a bug has been
fixed, and make sure to include yourself in the contributors list. :)

To prepare your environment, create a virtual environment and install ``pytest-qt`` in editable mode with ``dev``
extras::

    $ pip install --editable .[dev]

After that install ``pre-commit`` for pre-commit checks::

    $ pre-commit install

Running tests
-------------

Tests are run using `tox`_::

    $ tox -e py37-pyside2,py37-pyqt5

``pytest-qt`` is formatted using `black <https://github.com/ambv/black>`_ and uses
`pre-commit <https://github.com/pre-commit/pre-commit>`_ for linting checks before commits. You
can install ``pre-commit`` locally with::

    $ pip install pre-commit
    $ pre-commit install

Related projects
----------------

- `pytest-xvfb <https://github.com/The-Compiler/pytest-xvfb/>`_ allows to run a virtual xserver (Xvfb) on Linux to avoid GUI elements popping up on the screen or for easy CI testing
- `pytest-qml <https://github.com/jgirardet/pytest-qml>`_ allows running QML tests from pytest

Contributors
------------

Many thanks to:

- Igor T. Ghisi (`@itghisi <https://github.com/itghisi>`_);
- John David Reaver (`@jdreaver <https://github.com/jdreaver>`_);
- Benjamin Hedrich (`@bh <https://github.com/bh>`_);
- Benjamin Audren (`@baudren <https://github.com/baudren>`_);
- Fabio Zadrozny (`@fabioz <https://github.com/fabioz>`_);
- Datalyze Solutions (`@datalyze-solutions <https://github.com/datalyze-solutions>`_);
- Florian Bruhin (`@The-Compiler <https://github.com/The-Compiler>`_);
- Guilherme Quentel Melo (`@gqmelo <https://github.com/gqmelo>`_);
- Francesco Montesano (`@montefra <https://github.com/montefra>`_);
- Roman Yurchak (`@rth <https://github.com/rth>`_)
- Christian Karl (`@karlch <https://github.com/karlch>`_)

**Powered by**

.. |pycharm| image:: https://resources.jetbrains.com/storage/products/company/brand/logos/PyCharm.png
  :target: https://www.jetbrains.com/pycharm
  :width: 400

.. |pydev| image:: http://www.pydev.org/images/pydev_banner3.png
  :target: https://www.pydev.org

|pycharm|

|pydev|

.. _tox: https://tox.readthedocs.io

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/pytest-dev/pytest-qt",
    "name": "pytest-qt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "pytest qt test unittest",
    "author": "Bruno Oliveira",
    "author_email": "nicoddemus@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/53/2c/6a477108342bbe1f5a81a2c54c86c3efadc35f6ad47c76f00c75764a0f7c/pytest-qt-4.4.0.tar.gz",
    "platform": null,
    "description": "=========\npytest-qt\n=========\n\npytest-qt is a `pytest`_ plugin that allows programmers to write tests\nfor `PyQt5`_, `PyQt6`_, `PySide2`_ and `PySide6`_ applications.\n\nThe main usage is to use the ``qtbot`` fixture, responsible for handling ``qApp``\ncreation as needed and provides methods to simulate user interaction,\nlike key presses and mouse clicks:\n\n\n.. code-block:: python\n\n    def test_hello(qtbot):\n        widget = HelloWidget()\n        qtbot.addWidget(widget)\n\n        # click in the Greet button and make sure it updates the appropriate label\n        qtbot.mouseClick(widget.button_greet, qt_api.QtCore.Qt.MouseButton.LeftButton)\n\n        assert widget.greet_label.text() == \"Hello!\"\n\n\n.. _PySide2: https://pypi.org/project/PySide2/\n.. _PySide6: https://pypi.org/project/PySide6/\n.. _PyQt5: https://pypi.org/project/PyQt5/\n.. _PyQt6: https://pypi.org/project/PyQt6/\n.. _pytest: http://pytest.org\n\nThis allows you to test and make sure your view layer is behaving the way you expect after each code change.\n\n.. |version| image:: http://img.shields.io/pypi/v/pytest-qt.svg\n  :target: https://pypi.python.org/pypi/pytest-qt\n\n.. |conda-forge| image:: https://img.shields.io/conda/vn/conda-forge/pytest-qt.svg\n    :target: https://anaconda.org/conda-forge/pytest-qt\n\n.. |ci| image:: https://github.com/pytest-dev/pytest-qt/workflows/test/badge.svg\n  :target: https://github.com/pytest-dev/pytest-qt/actions\n\n.. |coverage| image:: http://img.shields.io/coveralls/pytest-dev/pytest-qt.svg\n  :target: https://coveralls.io/r/pytest-dev/pytest-qt\n\n.. |docs| image:: https://readthedocs.org/projects/pytest-qt/badge/?version=latest\n  :target: https://pytest-qt.readthedocs.io\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/pytest-qt.svg\n  :target: https://pypi.python.org/pypi/pytest-qt/\n  :alt: Supported Python versions\n\n.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n  :target: https://github.com/ambv/black\n\n|python| |version| |conda-forge| |ci| |coverage| |docs| |black|\n\n\nFeatures\n========\n\n- `qtbot`_ fixture to simulate user interaction with ``Qt`` widgets.\n- `Automatic capture`_ of ``qDebug``, ``qWarning`` and ``qCritical`` messages;\n- waitSignal_ and waitSignals_ functions to block test execution until specific\n  signals are emitted.\n- `Exceptions in virtual methods and slots`_ are automatically captured and\n  fail tests accordingly.\n\n.. _qtbot: https://pytest-qt.readthedocs.io/en/latest/reference.html#module-pytestqt.qtbot\n.. _Automatic capture: https://pytest-qt.readthedocs.io/en/latest/logging.html\n.. _waitSignal: https://pytest-qt.readthedocs.io/en/latest/signals.html\n.. _waitSignals: https://pytest-qt.readthedocs.io/en/latest/signals.html\n.. _Exceptions in virtual methods and slots: https://pytest-qt.readthedocs.io/en/latest/virtual_methods.html\n\nRequirements\n============\n\nSince version 4.1.0, ``pytest-qt`` requires Python 3.7+.\n\nWorks with either PySide6_, PySide2_, PyQt6_ or PyQt5_.\n\nIf any of the above libraries is already imported by the time the tests execute, that library will be used.\n\nIf not, pytest-qt will try to import and use the Qt APIs, in this order:\n\n- ``PySide6``\n- ``PySide2``\n- ``PyQt6``\n- ``PyQt5``\n\nTo force a particular API, set the configuration variable ``qt_api`` in your ``pytest.ini`` file to\n``pyside6``, ``pyside2``, ``pyqt6`` or ``pyqt5``:\n\n.. code-block:: ini\n\n    [pytest]\n    qt_api=pyqt5\n\n\nAlternatively, you can set the ``PYTEST_QT_API`` environment\nvariable to the same values described above (the environment variable wins over the configuration\nif both are set).\n\n\nDocumentation\n=============\n\nFull documentation and tutorial available at `Read the Docs`_.\n\n.. _Read The Docs: https://pytest-qt.readthedocs.io\n\nChange Log\n==========\n\nPlease consult the `changelog page`_.\n\n.. _changelog page: https://pytest-qt.readthedocs.io/en/latest/changelog.html\n\nBugs/Requests\n=============\n\nPlease report any issues or feature requests in the `issue tracker`_.\n\n.. _issue tracker: https://github.com/pytest-dev/pytest-qt/issues\n\nContributing\n============\n\nContributions are welcome, so feel free to submit a bug or feature\nrequest.\n\nPull requests are highly appreciated! If you\ncan, include some tests that exercise the new code or test that a bug has been\nfixed, and make sure to include yourself in the contributors list. :)\n\nTo prepare your environment, create a virtual environment and install ``pytest-qt`` in editable mode with ``dev``\nextras::\n\n    $ pip install --editable .[dev]\n\nAfter that install ``pre-commit`` for pre-commit checks::\n\n    $ pre-commit install\n\nRunning tests\n-------------\n\nTests are run using `tox`_::\n\n    $ tox -e py37-pyside2,py37-pyqt5\n\n``pytest-qt`` is formatted using `black <https://github.com/ambv/black>`_ and uses\n`pre-commit <https://github.com/pre-commit/pre-commit>`_ for linting checks before commits. You\ncan install ``pre-commit`` locally with::\n\n    $ pip install pre-commit\n    $ pre-commit install\n\nRelated projects\n----------------\n\n- `pytest-xvfb <https://github.com/The-Compiler/pytest-xvfb/>`_ allows to run a virtual xserver (Xvfb) on Linux to avoid GUI elements popping up on the screen or for easy CI testing\n- `pytest-qml <https://github.com/jgirardet/pytest-qml>`_ allows running QML tests from pytest\n\nContributors\n------------\n\nMany thanks to:\n\n- Igor T. Ghisi (`@itghisi <https://github.com/itghisi>`_);\n- John David Reaver (`@jdreaver <https://github.com/jdreaver>`_);\n- Benjamin Hedrich (`@bh <https://github.com/bh>`_);\n- Benjamin Audren (`@baudren <https://github.com/baudren>`_);\n- Fabio Zadrozny (`@fabioz <https://github.com/fabioz>`_);\n- Datalyze Solutions (`@datalyze-solutions <https://github.com/datalyze-solutions>`_);\n- Florian Bruhin (`@The-Compiler <https://github.com/The-Compiler>`_);\n- Guilherme Quentel Melo (`@gqmelo <https://github.com/gqmelo>`_);\n- Francesco Montesano (`@montefra <https://github.com/montefra>`_);\n- Roman Yurchak (`@rth <https://github.com/rth>`_)\n- Christian Karl (`@karlch <https://github.com/karlch>`_)\n\n**Powered by**\n\n.. |pycharm| image:: https://resources.jetbrains.com/storage/products/company/brand/logos/PyCharm.png\n  :target: https://www.jetbrains.com/pycharm\n  :width: 400\n\n.. |pydev| image:: http://www.pydev.org/images/pydev_banner3.png\n  :target: https://www.pydev.org\n\n|pycharm|\n\n|pydev|\n\n.. _tox: https://tox.readthedocs.io\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pytest support for PyQt and PySide applications",
    "version": "4.4.0",
    "project_urls": {
        "Homepage": "http://github.com/pytest-dev/pytest-qt"
    },
    "split_keywords": [
        "pytest",
        "qt",
        "test",
        "unittest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c516cc5b9c1ecdcd78e6cde97e03d05f5a4ace8f720c5ce0f26f9dce474a0da",
                "md5": "b058e5e538995e9388dc0287e23bf840",
                "sha256": "001ed2f8641764b394cf286dc8a4203e40eaf9fff75bf0bfe5103f7f8d0c591d"
            },
            "downloads": -1,
            "filename": "pytest_qt-4.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b058e5e538995e9388dc0287e23bf840",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 36286,
            "upload_time": "2024-02-07T21:22:13",
            "upload_time_iso_8601": "2024-02-07T21:22:13.295547Z",
            "url": "https://files.pythonhosted.org/packages/4c/51/6cc5b9c1ecdcd78e6cde97e03d05f5a4ace8f720c5ce0f26f9dce474a0da/pytest_qt-4.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "532c6a477108342bbe1f5a81a2c54c86c3efadc35f6ad47c76f00c75764a0f7c",
                "md5": "b8ba1020734678f26e926a0f5e3c20db",
                "sha256": "76896142a940a4285339008d6928a36d4be74afec7e634577e842c9cc5c56844"
            },
            "downloads": -1,
            "filename": "pytest-qt-4.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b8ba1020734678f26e926a0f5e3c20db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 125443,
            "upload_time": "2024-02-07T21:22:15",
            "upload_time_iso_8601": "2024-02-07T21:22:15.849248Z",
            "url": "https://files.pythonhosted.org/packages/53/2c/6a477108342bbe1f5a81a2c54c86c3efadc35f6ad47c76f00c75764a0f7c/pytest-qt-4.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-07 21:22:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-qt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "pytest-qt"
}
        
Elapsed time: 0.36608s