Simulte user input using doctest

Terry Reedy tjreedy at udel.edu
Mon Jun 23 14:10:12 EDT 2003


"Bartolomé Sintes Marco" <BartolomeSintes at ono.com> wrote in message
news:nAGJa.24271$FN3.1910022 at news.ono.com...
> Hi,
> Is it possible to simulate user input in a doctest docstring?
 > want to test if this module writes "Andy" when the user writes
"Andy".
> 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