import threading
import time


DEFAULT_SLEEP = 0.01


class CustomError(Exception):
    pass


def defer(callback, *args, **kwargs):
    sleep = kwargs.pop('sleep', DEFAULT_SLEEP)
    expected_return = kwargs.pop('expected_return', None)
    call = kwargs.pop('call', True)

    def func():
        time.sleep(sleep)
        if call:
            assert expected_return == callback(*args, **kwargs)
        else:
            print("generator is not re-called")

    t = threading.Thread(target=func)
    t.start()


def wait_until_finished(wrapper, timeout=1, sleep=DEFAULT_SLEEP):

    start_time = time.time()
    while time.time() < start_time + timeout:
        # Relies on .has_terminated, but shouldn't be a problem
        if wrapper.has_terminated():
            return
        time.sleep(sleep)

    raise RuntimeError("Has not been collected within %ss" % timeout)


class State(object):

    """Helper class to keep track of a test's state."""

    def __init__(self):
        self.reset()

    def inc(self):
        self.counter += 1

    def reset(self):
        self.counter = 0
        self.run = False

@@ -118,52 +118,25 @@
 rgs,
- **kwargs):%0A    sleep = kwargs.pop('
+%0A          
 sleep
-', 
+=
 DEFA
@@ -144,21 +144,17 @@
 LT_SLEEP
-)%0A   
+,
  expecte
@@ -165,83 +165,46 @@
 turn
- = kwargs.pop('expected_return', None)%0A    call = kwargs.pop('call', True)%0A
+=None, call=True,%0A          **kwargs):
 %0A   

Use named kwargs after *args