doctests for interactive functions

Brian van den Broek broek at cc.umanitoba.ca
Thu Feb 8 17:31:23 EST 2007


Neil Cerutti said unto the world upon 02/08/2007 02:25 PM:
> On 2007-02-08, Brian van den Broek <broek at cc.umanitoba.ca> wrote:
>> All classes take an optional argument input_function that
>> determines how the class instance gets its input. If this is
>> not provided, it defaults to raw_input. doctest tests reassign
>> it so that they can be run automatically.
> 
> What I've done in these cases is create a file containing my test
> input, and before running the doctests I remap sys.stdin to my
> file of test data. Then you don't need test code cluttering up
> your functions.
> 


Hi Neil and all,

Thanks for the suggestion, Neil. I will look into it.

I am not worried about the test code cluttering up my module's source, 
as I am using doctest.testfile to run doctests defined in a separate 
file anyway. I am looking to produce illustrative examples for the 
user manual which also can serve as tests. I'll play around and see if 
remapping sys.stdin reduces the gap between the appearance of the 
doctest examples and of actual use cases as compared to my current 
approach.

Thanks again,

Brian vdB




More information about the Python-list mailing list