traits_futures.testing.test_assistant module

Test support, providing the ability to run the event loop from within tests.

traits_futures.testing.test_assistant.SAFETY_TIMEOUT = 5.0

Maximum timeout for blocking calls, in seconds. A successful test should never hit this timeout - it’s there to prevent a failing test from hanging forever and blocking the rest of the test suite.

class traits_futures.testing.test_assistant.TestAssistant[source]

Bases: object

Convenience mixin class for tests that need the event loop.

This class is designed to be used as a mixin alongside unittest.TestCase for tests that need to run the event loop as part of the test.

Most of the logic is devolved to a toolkit-specific EventLoopHelper class.


Factory for the event loop.



Return type



Exercise the event loop.

Places a new task on the event loop and runs the event loop until that task is complete. The goal is to flush out any other tasks that might already be in event loop tasks queue.

Note that there’s no guarantee that this will execute other pending event loop tasks. So this method is useful for tests of the form “check that nothing bad happens as a result of other pending event loop tasks”, but it’s not safe to use it for tests that require pending event loop tasks to be processed.

run_until(object, trait, condition, timeout=5.0)[source]

Run event loop until the given condition holds true, or until timeout.

The condition is re-evaluated, with the object as argument, every time the trait changes.

  • object (traits.has_traits.HasTraits) – Object whose trait we monitor.

  • trait (str) – Name of the trait to monitor for changes.

  • condition – Single-argument callable, returning a boolean. This will be called with object as the only input.

  • timeout (float, optional) – Number of seconds to allow before timing out with an exception. The (somewhat arbitrary) default is 5 seconds.


RuntimeError – If timeout is reached, regardless of whether the condition is true or not at that point.