Example #1
0
    # kickstart the coroutine
    next(c)

    assert c.throw(MyException) == "foobar"

    # finish consumption of the coroutine if necessary
    for _ in c:
        pass


@pytest.mark.parametrize(
    "trace",
    [
        function_trace(name="simple_gen"),
        external_trace(library="lib", url="http://foo.com"),
        database_trace("select * from foo"),
        datastore_trace("lib", "foo", "bar"),
        message_trace("lib", "op", "typ", "name"),
        memcache_trace("cmd"),
    ],
)
def test_coroutine_functions_outside_of_transaction(trace):
    @trace
    def coro():
        for _ in range(2):
            yield "foo"

    assert [_ for _ in coro()] == ["foo", "foo"]

    c = coro()

    # kickstart the coroutine
    next(c)

    assert c.throw(MyException) == 'foobar'

    # finish consumption of the coroutine if necessary
    for _ in c:
        pass


@pytest.mark.parametrize('trace', [
    function_trace(name='simple_gen'),
    external_trace(library='lib', url='http://foo.com'),
    database_trace('select * from foo'),
    datastore_trace('lib', 'foo', 'bar'),
    message_trace('lib', 'op', 'typ', 'name'),
    memcache_trace('cmd'),
])
def test_coroutine_functions_outside_of_transaction(trace):
    @trace
    def coro():
        for _ in range(2):
            yield 'foo'

    assert [_ for _ in coro()] == ['foo', 'foo']


@validate_transaction_metrics(