Testing Widgets

Writing widget tests may seem a daunting task at first, as there are so many different functionalities a widget depends on while it operates. But as long as you keep in mind that widgets are independent of each other, you should be fine.

Whenever you feel that you need to construct a workflow to test the widget, stop, and think again. The only way widgets communicate with each other is through signals. If you need to construct a workflow to prepare the data and send it to the widget, prepare the data in code and pass it in. Same goes for outputs, get the value of the widget output and check that the assumptions about it hold.

In order to make your life easier, Orange provides a base class for unittest WidgetTest, which provides some helper methods.

Class Member Documentation

class Orange.widgets.tests.base.WidgetTest(methodName='runTest')[source]

Base class for widget tests

Contains helper methods widget creation and working with signals.

All widgets should be created by the create_widget method, as this will ensure they are created correctly.

widgets = []


classmethod setUpClass()[source]

Prepare environment for test execution

Construct a dummy signal manager and monkey patch OWReport.get_instance to return a manually created instance.


Process any pending events before the next test is executed.

create_widget(cls, stored_settings=None, reset_default_settings=True)[source]

Create a widget instance using mock signal_manager.

When used with default parameters, it also overrides settings stored on disk with default defined in class.

After widget is created, QApplication.process_events is called to allow any singleShot timers defined in __init__ to execute.

  • cls (WidgetMetaClass) – Widget class to instantiate
  • stored_settings (dict) – Default values for settings
  • reset_default_settings (bool) – If set, widget will start with default values for settings, if not, values accumulated through the session will be used

Widget instance

Return type:


static reset_default_settings()[source]

Reset default setting values for widget

Discards settings read from disk and changes stored by fast_save

Parameters:cls (OWWidget) – widget to reset settings for
process_events(until: <built-in function callable> = None, timeout=5000)[source]

Process Qt events, optionally until until returns something True-ish.

Needs to be called manually as QApplication.exec is never called.

  • until (callable or None) – If callable, the events are processed until the function returns something True-ish.
  • timeout (int) – If until condition is not satisfied within timeout milliseconds, a TimeoutError is raised.

Return type:

If until is not None, the True-ish result of its call.


Show widget in interactive mode.

Useful for debugging tests, as widget can be inspected manually.

send_signal(input, value, *args, widget=None, wait=-1)[source]

Send signal to widget by calling appropriate triggers.

  • input_name (str) –
  • value (Object) –
  • id (int) – channel id, used for inputs with flag Multiple
  • widget (Optional[OWWidget]) – widget to send signal to. If not set, self.widget is used
  • wait (int) – The amount of time to wait for the widget to complete.
get_output(output, widget=None)[source]

Return the last output that has been sent from the widget.

  • output_name (str) –
  • widget (Optional[OWWidget]) – widget whose output is returned. If not set, self.widget is used

Return type:

The last sent value of given output or None if nothing has been sent.


Context that simulates pressed modifiers

Since QTest.keypress requries pressing some key, we simulate pressing “BassBoost” that looks exotic enough to not meddle with anything.