async def test_subproc_capture_stdout_from_terminated_proc(run, verify_output):
    async def coro(ctx):
        argv = ctx.tjob.mock_argv(['sleep:30'])
        with ctx.tjob.subprocess_xevents(argv, result='terminate'):
            async with ctx.subprocess(argv, stdout=PIPE) as proc:
                return await proc.stdout.readline()
                # Skipping await proc.wait() to provoke termination

    todo = [TJob(name, coro=coro) for name in ['foo', 'bar']]
    done = await run(todo)
    assert verify_tasks(  # undecorated output was captured and returned
        done, {job.name: job.out.encode('ascii')
               for job in todo})
    assert verify_output([], [])  # subproc terminated before print to stderr
async def test_follow_file_outside_decoration_raises_RuntimeError(
        tmp_path, run, verify_output):
    path = tmp_path / 'file'
    path.write_text('\n'.join(['first line', 'second line', 'third line']))

    async def coro(ctx):
        with ctx.follow_file(path):
            pass

    todo = TUndecoratedJob('foo', coro=coro)
    done = await run([todo])
    assert verify_tasks(
        done,
        {'foo': RuntimeError('Cannot follow file outside decoration context')},
    )