Simulte user input using doctest

Terry Reedy tjreedy at
Mon Jun 23 20:10:12 CEST 2003

"Bartolomé Sintes Marco" <BartolomeSintes at> wrote in message
news:nAGJa.24271$FN3.1910022 at
> Hi,
> Is it possible to simulate user input in a doctest docstring?
 > want to test if this module writes "Andy" when the user writes
> What would be the docstring?
> def askyourname():
>     print "What's your name?",
>     myname = raw_input()
>     print myname

Not sure if you can do what you want with docstring,
but you can override the builtin raw_input() with your own version:

def raw_input(): return 'Andy'

Terry J. Reedy

More information about the Python-list mailing list