Skip to content

Integration with qtpy #184

Closed
Closed
@rth

Description

@rth

The support of multiple PyQt / PySide backends is a recurrent problem for any project working with Qt in Python. In pytest-qt it is solved by providing a compatibility _QtApi interface in qt_compat.py (that is not in the public interface). At the same time there are packages that specialize in providing such a compatibility interface, namely spyder-ide/qtpy and mottosso/Qt.py. For project that use one of those packages (e.g. matplotlib is considering it), and wanting to test it with with pytest-qt it would mean that they would not, technically be testing the project in the same conditions (and it would also mean setting differently named environment variables twice PYTEST_QT_API and QT_API or QT_PREFERRED_BINDING.)

I think the integration could be straightforward: e.g. to integrate with qtpy, the following should almost work,

At the end of pytestqt/qt_compat.py

try:
    if 'QT_API' not in os.environ and 'PYTEST_QT_API' in os.environ:
        os.environ['QT_API'] = os.environ['PYTEST_QT_API']
    import qtpy
    qt_api = qtpy
    qt_api.pytest_qt_api = qtpy.API
except ImportError:
     # fallback to the built-in compatibility layer..
    qt_api = _QtApi()

And maybe one extra environment in TravisCI for testing..

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions