# Implementing PyTest-qt

**URL:** <https://discourse.slicer.org/t/implementing-pytest-qt/28096>\
**Category:** Development\
**Tags:** testing\
**Created:** [February 28, 2023, 4:38pm UTC](https://discourse.slicer.org/t/implementing-pytest-qt/28096 "2023-02-28T16:38:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [February 28, 2023, 5:41pm UTC](https://discourse.slicer.org/t/implementing-pytest-qt/28096/2 "2023-02-28T17:41:06Z")

</div>

PyTest-qt summary:

> 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:

@jcfr @lassoan @pieper Do you have any thoughts about python testing of Slicer modules and their usage of simulated user interaction?

How does QtTesting fit into current recommendations?

- QtTesting and Python: [Macro XML to python - #2 by jcfr](https://discourse.slicer.org/t/macro-xml-to-python/15803/2)
- [Documentation/Nightly/SlicerApplication/QtTesting - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/SlicerApplication/QtTesting)
- [Documentation/Nightly/Developers/QtTesting - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Developers/QtTesting)

> Recording of macro using QtTesting should be considered experimental.  
> We suggest to implement workflow automation through Python scripts operating at a lower level by changing properties of MRML nodes and calling module logic functions

One of the above links has the above header. Does this mean it is not recommended to do this GUI level type of testing that uses simulated clicks and interactions? Slicer core appears to utilize some QtTesting in [qMRMLCheckableNodeComboBoxEventTranslatorPlayerTest1.xml](https://github.com/Slicer/Slicer/blob/main/Libs/MRML/Widgets/Testing/qMRMLCheckableNodeComboBoxEventTranslatorPlayerTest1.xml). I assume this is because it is a qMRML QObject rather than say a Slicer module.

Are [Self-tests](https://slicer.readthedocs.io/en/latest/user_guide/modules/selftests.html) the Slicer recommended way for scripted loadable module python testing? Is the `clickAndDrag` method the recommended manner for synthetic input into Slicer modules, or is something like PyTest-qt as mentioned in the original post a possibility for Slicer scripted module testing?

> <https://github.com/Slicer/Slicer/blob/2db14ceb03248e0fea6610bcdf059f4f24f6cc5a/Base/Python/slicer/util.py#L3028-L3085>

---

_[View the full topic](https://discourse.slicer.org/t/implementing-pytest-qt/28096)._
