Integration with qtpy
See original GitHub issueThe 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?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
There’s already some discussion about this at https://github.com/pytest-dev/pytest-qt/pull/130#issuecomment-219218794 FWIW.
Thanks for the pointer @machinekoder.
But as commented in https://github.com/pytest-dev/pytest-qt/pull/130#issuecomment-219218794 it is probably not worth to use a wrapper, the qt_compat module provides lazy loading and doesn’t really add too much to maintenance because we don’t need to import the entire API anyway, just a few symbols.