Q:

Why does 'yield' in a test case let the test pass

I am trying to understand the following python code snippet, taken from the SublimeText3 plugin development unit testing examples.
def test_delayed_insert(self):
    sublime.set_timeout(
        lambda: self.view.run_command("delayed_insert_hello_world"),
        100)
    # `delayed_insert_hello_world` will be execulated after the timeout
    # `yield 1000` will yield the runtime to main thread and continue
    # the execution 1 second later
    yield 1000
    row = self.getRow(0)
    self.assertEqual(row, "hello world")

How can this work? If unittest does not support this (call the test as a generator), the code would not be executed, right?
My current understanding is the unittest framework takes the yielded value 'x', and suspends itself for 'x' ms, in this case 1000ms, similar to the semantics of yield/sleep in c++ threads. However, that depends on 'unittest' to really use the yielded value in this way.
If it does, why does this test not fail (tried it within st3 = python 3.3.6 and python 3.5.2) ?
from unittest import TestCase

class TestMe(TestCase):
    def test_failtest(self):
        self.assertTrue(False)
        yield 0

Running it gives:
~$ python3 -m unittest test_me.py --verbose
test_failtest (test_me.TestMe) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

A:

TL;DR the code you linked to is subclassing a custom TestCase class (DeferrableTestCase) which may alter the "normal" behavior of unittest.
Let's take a step back and not use unittest.
def foo():
    assert True is False

foo()

This raises an AssertionError as expected. However,
def foo():
    assert True is False
    yield

foo()

Does not.
The reason is that the yield keyword turns foo to a generator.
In order to get the AssertionError we would have to consume the generator that foo returns:
def foo():
    assert True is False
    yield

next(foo())
  File "main.py", line 48, in <module>
next(foo())
  File "main.py", line 45, in foo
assert True is False
AssertionError

This behavior is inherit to generators and not related to how unittest or assert work:
def foo():
    1/0
    yield

gen = foo()
print('No exception yet')
next(gen)

Outputs
'No exception yet'
Traceback (most recent call last):
File "main.py", line 50, in <module>
  next(gen)
File "main.py", line 45, in foo
  1/0
ZeroDivisionError: division by zero

However, the code you linked to is subclassing a custom TestCase class (DeferrableTestCase) which may alter the behavior.

