Pytest and

Can someone help me understand how best to set up a testing environment for sg apps?

I’m using pytest and wanting to import a module that has from sgtk.platform.qt import QtCore, QtGui at the top of the file.

If running via a pytest that imports this module, I get ERROR tests/test_dm.py::test_update_model - ImportError: cannot import name 'QtCore'

I’m able to import sgtk, I have tk-core in my environment and I’ve installed PyQt5 and PySide2. Both of which I can import in my venv python session.

What pre-requisites do I need for “from sgtk.platform.qt import QtCore, QtGui” to work?

OR

What do I need to wrap this line in (try/except) to allow me to proceed with testing methods within this module?

Thanks in advance for any pointers.

Have not tried this with pytests, let alone have a working test setup for sgtk apps. But I think to get “from sgtk.platform.qt import QtCore, QtGui” to work you probably have to bootstrap an engine since this Qt module serves as a consistent layer between the various pyqt and pyside flavours of all the DCC’s.

Hope that helps :slightly_smiling_face:

Cheers

Hi @Patrick

I believe that the underlying issue is that PySide2 is not available in your python environment.

Either use the python binary that comes with SG Desktop, or do pip install PySide2

Hoping this helps,

-Patrick

Patrick is probably right, you might have PySide installed, but it is missing in your path.

We use tox for tests and it installs dependencies in a separate environment when running tests (read from setup.py).
Haven’t tried this in sg apps, though.

Thanks guys, I’ll give it another go. I do have PySide installed, but perhaps it’s not pathed up correctly. I’m running my tests from within a venv with specific packages installed.
Thanks again.
p.