Testing¶
UI test framework, see the module overview below for usage and for why some helpers are not built on QTest.
UI test framework for Qt widgets: from zoo.libs.pyqt import testing. Python 3.7 compatible.
Runs the same test in plain Python (offscreen), in mayapy and in interactive Maya, on PySide2 5.15 and PySide6.
Usage¶
from zoo.libs.pyqt import testing
from zoo.libs.pyqt.testing import QtTestCase
from zoovendor.Qt import QtWidgets
class TestButton(QtTestCase):
def test_clickEmitsClicked(self):
button = self.track(QtWidgets.QPushButton("ok")) # closed and deleted after the test
clicks = testing.collectSignal(button.clicked) # list of emitted args
testing.showAndWait(button) # show and wait until exposed
testing.click(button)
self.assertEqual(len(clicks), 1)
@testing.requiresHost # skipped without maya.cmds
def test_needsMaya(self):
...
Rules: create every top level widget through self.track(); wait on conditions with testing.waitFor instead of
fixed sleeps; assert visibility, relative geometry, signals and model state, never pixel exact output (offscreen fonts
and DPI differ). QtTestCase creates one shared offscreen QApplication, never a second. Set ZOO_NO_QTESTS=1
to skip all Qt tests. Classes carry zooQtTest = True so runners can filter them.
testing.stubPreferences() runs on import: a few widgets read the Zoo preference manager at import, which is
None until Zoo starts. The stub is only installed when it is still None and the session is not a real GUI (interactive Maya), so a live
Zoo session is never touched; removeStubPreferences() undoes it and never removes a real manager.
Why some helpers do not use QTest¶
QTest is used where it behaves the same on every binding: click, keyClick, keyClicks and
showAndWait (qWaitForWindowExposed). These are not built on it:
doubleClickalways sends press, release, double click and release events.QTest.mouseDClicksends a different sequence on Qt5 and Qt6 and widgets which count presses see the difference.contextMenu,hover,leaveandwheelsend the events directly, the offscreen platform does not turn a right click into a context menu event andQTesthas no wheel helper.runWithPopupandrunWithWindowrun a trigger which blocks (QMenu.exec_,QDialog.exec_, a ZooMessageBoxwaiting in a loop ofprocessEvents): a timer finds the popup, lets the test look at it or press its buttons, then closes it so the trigger returns.waitForpolls withprocessEvents.QTest.qWaitFordoes not exist in PySide2 5.15 (Maya 2022 to 2024).dragsendsQMouseEventobjects directly.QTest.mouseMovedoes not carry the held button reliably, so a drag handler never sees a press-move-release with the button down, especially on the offscreen platform.collectSignalrecords into a plain list.QSignalSpyis not reliable across PySide2 and PySide6.settleruns the event loop for a fixed time, for delayed refreshes only.QTest.qWaitblocks differently.Model checks use our own contract helpers (
assertModelContract,recordModelSignals, intesting.models):QAbstractItemModelTesteris not in PySide2 5.15 nor in Maya 2027.qtModelTesterattaches it where it exists.
When QtTest is missing¶
Maya 2027 ships PySide6 6.8.3 without the QtTest module (Qt6Test.dll is in bin but there is no
binding for it), so zoovendor.Qt cannot expose QtTest however its member list is edited, and importing it
would stop every Qt test from loading. helpers therefore treats QtTest as optional. Without it:
clickanddoubleClicksendQMouseEventpress, release (and double click) events to the widget, at the widget center when no position is given.keyClickandkeyClickssendQKeyEventpress and release events straight to the widget, asQTestdoes. They carry the character as text, so line edits and text edits receive typed text; shortcuts and focus handling are not emulated.showAndWaitshows the widget and polls until its window handle reportsisExposed().
The fallbacks cover what the QTest helpers cover for widget tests, so tests are written once and run on every Maya
version. tests/test_qttesting.py runs the helper tests with QtTest forced absent, so the fallbacks are
exercised on every version, not only on 2027.
Everything is imported through zoovendor.Qt so tests never name a binding.
- class QtTestCase(methodName='runTest')¶
Base for tests which need widgets. Runs standalone (offscreen) and in mayapy or Maya.
Skips when ZOO_NO_QTESTS=1. Pass every top level widget to
track()so it is closed after the test, or a window every test of the class shares totrackClass()so it is closed after the class.Qt objects must die while the QApplication is alive. A Python owned QObject in a reference cycle (a model and its data sources, a data source and its children) is only freed by the cycle collector, and when that first runs at interpreter shutdown the QApplication is already gone: interactive Maya then crashes on exit with an access violation and no crash log. So
tearDowndrops the Qt objects a test stored on itself (the test result keeps test instances alive) andtearDownClasscollects the cycles and runs the pendingdeleteLater()calls.Zoo windows are parented to the host’s main window and closing a frameless window only hides its container, so every Zoo top level window the class opened (and didn’t track) is deleted in
tearDownClasstoo. Dozens of hidden windows left under Maya’s main window crash Maya when it quits. Set the Qt propertyzooTestKeepto True on a window which must outlive the class (the shared demo window).zoo.libs.pyqt.utils.currentScreenGeometry()returnsfixtures.TEST_SCREEN_GEOMETRYduring the class, so code which keeps windows inside the screen behaves the same on every machine, Qt binding and host.- KEEP_PROPERTY = 'zooTestKeep'¶
Qt property which keeps a top level window alive after the class, see the class docstring
- patchFrameIcons()¶
Patch the collapsable frame icons for this test, the engine icons aren’t needed
- classmethod setUpClass()¶
Skips the class when ZOO_NO_QTESTS=1, otherwise gets the shared QApplication as
cls.app- Raises:
unittest.SkipTest – if Qt tests are disabled or the running application is not a QApplication
- tearDown()¶
Closes and deletes the tracked widgets, then runs the event loop once
- classmethod tearDownClass()¶
Deletes the Zoo windows the class left open and frees the Qt objects left in reference cycles, while the QApplication is alive, see the class docstring
- track(widget)¶
Register a widget to be closed and deleted in tearDown
- Returns:
the widget
- classmethod trackClass(widget)¶
Register a widget shared by every test of the class, usually created in
setUpClass. It stays open between the tests, like a window a user keeps open, and is closed and deleted intearDownClass. Reset the state a test changes insetUpso the tests don’t depend on their order.- Returns:
the widget
- zooQtTest = True¶
marks the class as a Qt test for runners which filter
- requiresHost(obj)¶
Skip unless maya.cmds can be imported
- requiresGui(obj)¶
Skip unless running in a real GUI session (interactive Maya)
- stubPreferences()¶
Make
zoo.preferences.core.preferenceusable when Zoo has not started.A few widgets (
buttons,groupedtreewidget) read the preference manager at import, and it is None until Zoo starts. A stub is only installed when ALL of these hold, so a live session is never touched:the preference manager is still None (Zoo has not set it up)
this is not a real GUI session (interactive Maya, see
environment.isGui())
Temporary: goes away when widgets stop reading preferences at import. Undo with
removeStubPreferences().- Returns:
True if a stub was installed
- Return type:
- removeStubPreferences()¶
Remove the stub made by
stubPreferences(), only if it is still the one installed (never a real manager)- Returns:
True if a stub was removed
- Return type:
- stubEngine()¶
Make
zoo.core.engine.currentEngine()usable when Zoo has not started, soiconliband dialogs work.The icon library asks the engine whether the host is headless. A stub (a non headless host) is installed only when there is no engine and this is not a real GUI session. Undo with
removeStubEngine().- Returns:
True if a stub was installed
- Return type:
- removeStubEngine()¶
Remove the engine made by
stubEngine(), only if it is still the current one- Returns:
True if a stub was removed
- Return type:
- stubHeadlessHost()¶
Make a headless host report that it is not, for the test process only.
mayapyis a headless host:iconlib.icon()returnsNonethere, so every Zoo widget which sets an icon (the title bar of aZooWindow, the buttons) fails to build. The widgets are created on an offscreenQApplicationin the tests, so the icons are needed. Not done in a real GUI session, where the host is not headless anyway. Undo withremoveStubHeadlessHost().- Returns:
True if the host was patched
- Return type:
- removeStubHeadlessHost()¶
Undo
stubHeadlessHost()- Returns:
True if the patch was removed
- Return type:
- noFrameIcons()¶
The collapsable frame icons come from the icon engine, which tests don’t need
- fixedScreenGeometry(geometry=(0, 0, 1920, 1080))¶
Context manager version of
fixedScreenGeometryPatcher()
- fixedScreenGeometryPatcher(geometry=(0, 0, 1920, 1080))¶
The patcher which makes
zoo.libs.pyqt.utils.currentScreenGeometry()return the same screen everywhere.Positions are contained in the screen, so tests which place windows would depend on the size of the offscreen screen of the Qt binding or Maya version they run on. Only the tests are affected,
start()andstop()it.
- settle(ms=80)¶
Run the event loop for ms milliseconds so delayed refreshes run, always at least once so
settle(0)runs the pending events
- waitFor(predicate, timeout=2000)¶
Process events until predicate() is true.
Polls instead of using QTest.qWaitFor, which PySide2 5.15 does not have.
- Parameters:
predicate – callable returning bool
timeout – max wait in milliseconds
- Returns:
True if the predicate became true
- Return type:
- showAndWait(widget)¶
Show the widget and wait until it is exposed
- click(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)¶
QTest mouse click on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget to click
button – The mouse button
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
modifier – Keyboard modifier held during the click
- doubleClick(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None)¶
QTest mouse double click on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget to double click
button – The mouse button
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- keyClick(widget, key, modifier=MockExt.QtCore.Qt.NoModifier)¶
QTest key press and release on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget which gets the key
key – A QtCore.Qt.Key
modifier – Keyboard modifier held during the key
- keyClicks(widget, text)¶
QTest types the text into the widget, one key click per character
- Parameters:
widget (QtWidgets.QWidget) – The widget which gets the keys
text (str) – The text to type
- drag(widget, start, end, button=MockExt.QtCore.Qt.LeftButton, steps=5)¶
Press at start, move to end in steps with the button held, release. Positions are QPoints in widget coordinates. Sends the events directly: QTest.mouseMove does not report the held button reliably.
- resizeAndSettle(widget, width, height, ms=40)¶
Resize the widget then run the event loop so layouts and delayed refreshes follow
- Parameters:
widget (QtWidgets.QWidget) – The widget to resize
width – New width in pixels
height – New height in pixels
ms – How long to run the event loop, in milliseconds
- collectSignal(signal)¶
A list which records the args of every emission. A plain list on purpose: QSignalSpy is not reliable across PySide2 and PySide6
- Returns:
list of tuples of emitted args
- Return type:
- grabImage(widget)¶
A QImage of the widget, for smoke checks only (no pixel exact asserts: fonts and DPI differ)
- runWithPopup(trigger, inspect=None, timeout=2000)¶
Call
triggerwhich opens a blocking popup or modal (QMenu.exec_,QDialog.exec_), look at the popup then close it, so the trigger returns. A test would hang forever on a blocking popup otherwise.A timer polls for
QApplication.activePopupWidget()thenactiveModalWidget(). When one is foundinspect(widget)runs (if given) and the widget is closed. When none appears withintimeoutms the trigger is left alone (it cannot be interrupted if it does block), so only use this for triggers which open a popup.- Parameters:
trigger – callable which opens the popup, eg
lambda: testing.click(button)inspect – callable receiving the popup, its return value is returned by this function
timeout – max wait for the popup in milliseconds
- Returns:
the result of
inspect, the popup ifinspectis None, None if no popup appeared
- runWithWindow(trigger, windowType, inspect=None, timeout=2000)¶
Like
runWithPopup()for blocking windows which are not Qt popups or modals, eg a window which waits in a loop ofprocessEventsuntil it is closed (MessageBox.showQuestion).A timer polls the top level widgets (and their children, as frameless windows live in a container) for a visible instance of
windowType. When foundinspect(window)runs (it may click the window’s buttons, which closes it) and the window is closed if it is still open.- Parameters:
trigger – callable which shows the window and blocks until it is closed
windowType – class (or tuple of classes) of the window to wait for
inspect – callable receiving the window, its return value is returned by this function
timeout – max wait for the window in milliseconds
- Returns:
the result of
inspect, the window ifinspectis None, None if no window appeared
- contextMenu(widget, pos=None)¶
Send a context menu event (what a right click does on a real platform: the offscreen platform does not turn a right button click into one), so
customContextMenuRequestedandcontextMenuEventrun- Parameters:
widget (QtWidgets.QWidget) – The widget to ask
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- hover(widget, pos=None)¶
Move the mouse onto the widget: sends an enter event then a mouse move without buttons
- Parameters:
widget (QtWidgets.QWidget) – The widget to hover
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- leave(widget)¶
Move the mouse off the widget: sends a leave event
- wheel(widget, delta=120, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)¶
Scroll the mouse wheel over the widget. 120 is one notch up, -120 one notch down.
- Parameters:
widget (QtWidgets.QWidget) – The widget under the cursor
delta (int) – Vertical angle delta in 1/8 degrees
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
modifier – Keyboard modifier held, eg Ctrl
- assertModelContract(model, maxDepth=4, maxRows=100)¶
Raise AssertionError listing every problem
modelContractProblems()finds- Parameters:
model (
QtCore.QAbstractItemModel) – the model to check
- modelContractProblems(model, maxDepth=4, maxRows=100)¶
Walk the model and return every broken item model rule.
Checked for the root and every index down to
maxDepthlevels (only the firstmaxRowsrows of a parent): counts are not negative, out of range indexes are invalid,index()is stable and points back at its row, column and model,parent()of a child is the index it was made from,sibling()agrees withindex(),hasChildren()agrees withrowCount(), anddata(),flags()andheaderData()do not raise and return types a view accepts. Parents which can fetch more rows are not walked, fetching would change the model.
- recordModelSignals(model)¶
Record the change signals of
modelinside thewithblock.with testing.recordModelSignals(model) as recorder: model.removeRows(0, 1) recorder.assertValid()
- Parameters:
model (
QtCore.QAbstractItemModel) – the model to watch- Return type:
- class ModelSignalRecorder(model)¶
Records the change signals of a model and checks that they keep the contract.
Made by
recordModelSignals(). Every begin signal (rowsAboutToBeInserted…) must be followed by its end signal with the same arguments before another change starts, and inserts and removes must change the row or column count by what the signals announced.- assertValid()¶
Raise AssertionError listing every problem
- connect()¶
- disconnect()¶
- problems()¶
Every broken rule, including begin signals which never got their end signal
- emitted¶
(signal name, args) in the order they were emitted
- qtModelTester(model)¶
Attach Qt’s
QAbstractItemModelTesterto the model, when this binding has it.It is not in PySide2 5.15 or in Maya 2027 (no
QtTest). It reports through Qt warnings, in Warning mode so a failure never aborts the process. Keep the returned object alive while the model is used.- Returns:
the tester, None when the binding has none
Case¶
The QtTestCase base class.
- class QtTestCase(methodName='runTest')¶
Bases:
TestCaseBase for tests which need widgets. Runs standalone (offscreen) and in mayapy or Maya.
Skips when ZOO_NO_QTESTS=1. Pass every top level widget to
track()so it is closed after the test, or a window every test of the class shares totrackClass()so it is closed after the class.Qt objects must die while the QApplication is alive. A Python owned QObject in a reference cycle (a model and its data sources, a data source and its children) is only freed by the cycle collector, and when that first runs at interpreter shutdown the QApplication is already gone: interactive Maya then crashes on exit with an access violation and no crash log. So
tearDowndrops the Qt objects a test stored on itself (the test result keeps test instances alive) andtearDownClasscollects the cycles and runs the pendingdeleteLater()calls.Zoo windows are parented to the host’s main window and closing a frameless window only hides its container, so every Zoo top level window the class opened (and didn’t track) is deleted in
tearDownClasstoo. Dozens of hidden windows left under Maya’s main window crash Maya when it quits. Set the Qt propertyzooTestKeepto True on a window which must outlive the class (the shared demo window).zoo.libs.pyqt.utils.currentScreenGeometry()returnsfixtures.TEST_SCREEN_GEOMETRYduring the class, so code which keeps windows inside the screen behaves the same on every machine, Qt binding and host.- KEEP_PROPERTY = 'zooTestKeep'¶
Qt property which keeps a top level window alive after the class, see the class docstring
- zooQtTest = True¶
marks the class as a Qt test for runners which filter
- classmethod setUpClass()¶
Skips the class when ZOO_NO_QTESTS=1, otherwise gets the shared QApplication as
cls.app- Raises:
unittest.SkipTest – if Qt tests are disabled or the running application is not a QApplication
- tearDown()¶
Closes and deletes the tracked widgets, then runs the event loop once
- classmethod tearDownClass()¶
Deletes the Zoo windows the class left open and frees the Qt objects left in reference cycles, while the QApplication is alive, see the class docstring
- track(widget)¶
Register a widget to be closed and deleted in tearDown
- Returns:
the widget
- classmethod trackClass(widget)¶
Register a widget shared by every test of the class, usually created in
setUpClass. It stays open between the tests, like a window a user keeps open, and is closed and deleted intearDownClass. Reset the state a test changes insetUpso the tests don’t depend on their order.- Returns:
the widget
- patchFrameIcons()¶
Patch the collapsable frame icons for this test, the engine icons aren’t needed
Helpers¶
Event loop and input helpers. Wait on conditions, never on fixed sleeps.
- settle(ms=80)¶
Run the event loop for ms milliseconds so delayed refreshes run, always at least once so
settle(0)runs the pending events
- waitFor(predicate, timeout=2000)¶
Process events until predicate() is true.
Polls instead of using QTest.qWaitFor, which PySide2 5.15 does not have.
- Parameters:
predicate – callable returning bool
timeout – max wait in milliseconds
- Returns:
True if the predicate became true
- Return type:
- showAndWait(widget)¶
Show the widget and wait until it is exposed
- click(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)¶
QTest mouse click on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget to click
button – The mouse button
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
modifier – Keyboard modifier held during the click
- contextMenu(widget, pos=None)¶
Send a context menu event (what a right click does on a real platform: the offscreen platform does not turn a right button click into one), so
customContextMenuRequestedandcontextMenuEventrun- Parameters:
widget (QtWidgets.QWidget) – The widget to ask
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- hover(widget, pos=None)¶
Move the mouse onto the widget: sends an enter event then a mouse move without buttons
- Parameters:
widget (QtWidgets.QWidget) – The widget to hover
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- leave(widget)¶
Move the mouse off the widget: sends a leave event
- wheel(widget, delta=120, pos=None, modifier=MockExt.QtCore.Qt.NoModifier)¶
Scroll the mouse wheel over the widget. 120 is one notch up, -120 one notch down.
- Parameters:
widget (QtWidgets.QWidget) – The widget under the cursor
delta (int) – Vertical angle delta in 1/8 degrees
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
modifier – Keyboard modifier held, eg Ctrl
- doubleClick(widget, button=MockExt.QtCore.Qt.LeftButton, pos=None)¶
QTest mouse double click on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget to double click
button – The mouse button
pos (QtCore.QPoint or None) – Position in widget coordinates, None for the center
- keyClick(widget, key, modifier=MockExt.QtCore.Qt.NoModifier)¶
QTest key press and release on the widget
- Parameters:
widget (QtWidgets.QWidget) – The widget which gets the key
key – A QtCore.Qt.Key
modifier – Keyboard modifier held during the key
- keyClicks(widget, text)¶
QTest types the text into the widget, one key click per character
- Parameters:
widget (QtWidgets.QWidget) – The widget which gets the keys
text (str) – The text to type
- drag(widget, start, end, button=MockExt.QtCore.Qt.LeftButton, steps=5)¶
Press at start, move to end in steps with the button held, release. Positions are QPoints in widget coordinates. Sends the events directly: QTest.mouseMove does not report the held button reliably.
- resizeAndSettle(widget, width, height, ms=40)¶
Resize the widget then run the event loop so layouts and delayed refreshes follow
- Parameters:
widget (QtWidgets.QWidget) – The widget to resize
width – New width in pixels
height – New height in pixels
ms – How long to run the event loop, in milliseconds
- collectSignal(signal)¶
A list which records the args of every emission. A plain list on purpose: QSignalSpy is not reliable across PySide2 and PySide6
- Returns:
list of tuples of emitted args
- Return type:
- runWithPopup(trigger, inspect=None, timeout=2000)¶
Call
triggerwhich opens a blocking popup or modal (QMenu.exec_,QDialog.exec_), look at the popup then close it, so the trigger returns. A test would hang forever on a blocking popup otherwise.A timer polls for
QApplication.activePopupWidget()thenactiveModalWidget(). When one is foundinspect(widget)runs (if given) and the widget is closed. When none appears withintimeoutms the trigger is left alone (it cannot be interrupted if it does block), so only use this for triggers which open a popup.- Parameters:
trigger – callable which opens the popup, eg
lambda: testing.click(button)inspect – callable receiving the popup, its return value is returned by this function
timeout – max wait for the popup in milliseconds
- Returns:
the result of
inspect, the popup ifinspectis None, None if no popup appeared
- runWithWindow(trigger, windowType, inspect=None, timeout=2000)¶
Like
runWithPopup()for blocking windows which are not Qt popups or modals, eg a window which waits in a loop ofprocessEventsuntil it is closed (MessageBox.showQuestion).A timer polls the top level widgets (and their children, as frameless windows live in a container) for a visible instance of
windowType. When foundinspect(window)runs (it may click the window’s buttons, which closes it) and the window is closed if it is still open.- Parameters:
trigger – callable which shows the window and blocks until it is closed
windowType – class (or tuple of classes) of the window to wait for
inspect – callable receiving the window, its return value is returned by this function
timeout – max wait for the window in milliseconds
- Returns:
the result of
inspect, the window ifinspectis None, None if no window appeared
- grabImage(widget)¶
A QImage of the widget, for smoke checks only (no pixel exact asserts: fonts and DPI differ)
Decorators¶
Decorators which skip a test, instead of failing it, when the host or GUI it needs is missing.
- requiresHost(obj)¶
Skip unless maya.cmds can be imported
- requiresGui(obj)¶
Skip unless running in a real GUI session (interactive Maya)
Fixtures¶
Stand-ins for engine pieces which widgets reach at import or construction time.
- class StubThemeInterface(theme=None)¶
Stands in for the
core_interfacepreference interface when Zoo has not started.Reads the default theme from the zoo_preferences
stylesheet.prefandzootools_style.qsswhen that package is installed, so widgets get real theme colors (BUTTON_ICON_COLOR) and a real stylesheet. Anything else is aMagicMock. Without zoo_preferences the stylesheet is empty and every theme value is aMagicMock.- stylesheet(theme=None)¶
- Return type:
- property themeUpdated¶
Signal emitting the theme update event, nothing emits it in tests unless the test does
- stubPreferences()¶
Make
zoo.preferences.core.preferenceusable when Zoo has not started.A few widgets (
buttons,groupedtreewidget) read the preference manager at import, and it is None until Zoo starts. A stub is only installed when ALL of these hold, so a live session is never touched:the preference manager is still None (Zoo has not set it up)
this is not a real GUI session (interactive Maya, see
environment.isGui())
Temporary: goes away when widgets stop reading preferences at import. Undo with
removeStubPreferences().- Returns:
True if a stub was installed
- Return type:
- removeStubPreferences()¶
Remove the stub made by
stubPreferences(), only if it is still the one installed (never a real manager)- Returns:
True if a stub was removed
- Return type:
- stubEngine()¶
Make
zoo.core.engine.currentEngine()usable when Zoo has not started, soiconliband dialogs work.The icon library asks the engine whether the host is headless. A stub (a non headless host) is installed only when there is no engine and this is not a real GUI session. Undo with
removeStubEngine().- Returns:
True if a stub was installed
- Return type:
- removeStubEngine()¶
Remove the engine made by
stubEngine(), only if it is still the current one- Returns:
True if a stub was removed
- Return type:
- stubHeadlessHost()¶
Make a headless host report that it is not, for the test process only.
mayapyis a headless host:iconlib.icon()returnsNonethere, so every Zoo widget which sets an icon (the title bar of aZooWindow, the buttons) fails to build. The widgets are created on an offscreenQApplicationin the tests, so the icons are needed. Not done in a real GUI session, where the host is not headless anyway. Undo withremoveStubHeadlessHost().- Returns:
True if the host was patched
- Return type:
- removeStubHeadlessHost()¶
Undo
stubHeadlessHost()- Returns:
True if the patch was removed
- Return type:
- TEST_SCREEN_GEOMETRY = (0, 0, 1920, 1080)¶
left, top, width, height of the screen the Qt tests run on, the real screen differs per machine, Qt binding and host
- fixedScreenGeometryPatcher(geometry=(0, 0, 1920, 1080))¶
The patcher which makes
zoo.libs.pyqt.utils.currentScreenGeometry()return the same screen everywhere.Positions are contained in the screen, so tests which place windows would depend on the size of the offscreen screen of the Qt binding or Maya version they run on. Only the tests are affected,
start()andstop()it.
- fixedScreenGeometry(geometry=(0, 0, 1920, 1080))¶
Context manager version of
fixedScreenGeometryPatcher()
- noFrameIcons()¶
The collapsable frame icons come from the icon engine, which tests don’t need
Environment¶
Detects what the test process offers (Maya, a GUI session) and creates the shared QApplication.
- isGui()¶
If this is a real GUI session: a QApplication exists and it is not on a headless platform
- Return type:
- ensureApplication()¶
The shared QApplication, created offscreen if there is none. Never creates a second one.
- Raises:
unittest.SkipTest – if the running application is not a QApplication, widgets can’t be created
- Return type:
QtWidgets.QApplication