void () { runPythonTest(new PyConsoleTask() { private static final int TIMEOUT = 3000; private static final int NUMBER_OF_ATTEMPTS = 10; @Override public void testing() throws Exception { exec("foo = 'bar'"); waitForConditionIsTrue("`foo` is not in the console variable tree", (root) -> { for(TreeNode child : root.getChildren()) { XDebuggerTreeNode node = (XDebuggerTreeNode) child; if (node.toString().equals("foo")) { return true; } } return false; }); exec("foo = 'baz'"); waitForConditionIsTrue("`foo` value hasn't changed to 'baz'", (root) -> { for(TreeNode child : root.getChildren()) { XDebuggerTreeNode node = (XDebuggerTreeNode) child; if (node.toString().equals("foo") && node.getText().toString().contains("'baz'")) { return true; } } return false; }); exec("del foo"); waitForConditionIsTrue("`foo` is still in the console variable tree", (root) -> { for (TreeNode child : root.getChildren()) { XDebuggerTreeNode node = (XDebuggerTreeNode)child; if (node.toString().equals("foo")) { return false; } } return true; }); } private void waitForConditionIsTrue(String message, @NotNull Predicate<XDebuggerTreeNode> pred) throws InterruptedException { final long startedAt = System.currentTimeMillis(); do { if (pred.test(getConsoleView().getDebuggerTreeRootNode())) return; Thread.sleep(TIMEOUT / NUMBER_OF_ATTEMPTS); } while (startedAt + TIMEOUT > System.currentTimeMillis()); Assert.fail(message); } }); }