# Pytest and

**URL:** <https://community.shotgridsoftware.com/t/pytest-and/14101>\
**Category:** Pipeline Integrations\
**Created:** [November 30, 2021, 6:24pm UTC](https://community.shotgridsoftware.com/t/pytest-and/14101 "2021-11-30T18:24:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [November 30, 2021, 6:24pm UTC](https://community.shotgridsoftware.com/t/pytest-and/14101/1 "2021-11-30T18:24:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fabian](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/fabian/32/3508_2.png) [@Fabian](https://community.shotgridsoftware.com/u/Fabian)\
**Post date:** [November 30, 2021, 8:04pm UTC](https://community.shotgridsoftware.com/t/pytest-and/14101/2 "2021-11-30T20:04:29Z")

</div>

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 🙂

Cheers

---

<div class="post-metadata">

**Author:** ![patrick-hubert-adsk](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick-hubert-adsk/32/257_2.png) [@patrick-hubert-adsk](https://community.shotgridsoftware.com/u/patrick-hubert-adsk)\
**Post date:** [December 1, 2021, 12:23am UTC](https://community.shotgridsoftware.com/t/pytest-and/14101/3 "2021-12-01T00:23:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mmoshev](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/mmoshev/32/476_2.png) [@mmoshev](https://community.shotgridsoftware.com/u/mmoshev)\
**Post date:** [December 1, 2021, 9:00am UTC](https://community.shotgridsoftware.com/t/pytest-and/14101/4 "2021-12-01T09:00:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Patrick](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/patrick/32/4767_2.png) [@Patrick](https://community.shotgridsoftware.com/u/Patrick)\
**Post date:** [December 9, 2021, 8:31pm UTC](https://community.shotgridsoftware.com/t/pytest-and/14101/5 "2021-12-09T20:31:20Z")

</div>

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.
