'doctest monkeypatches linecache to enable inspection'

def test_proceed_with_fake_filename(self):

    (fn, source) = ('<test>', 'def    x():    pass\n')
    getlines = linecache.getlines
    def monkey(filename, module_globals=None):
        if (filename == fn):
            return source.splitlines(True)
        else:
            return getlines(filename, module_globals)
    linecache.getlines = monkey
    try:
        ns = {}
        exec compile(source, fn, 'single') in ns
        inspect.getsource(ns['x'])
    finally:
        linecache.getlines = getlines
