[Tutor] Driving a CLI for testing

Alan Gauld alan.gauld at yahoo.co.uk
Fri Jun 23 20:33:09 EDT 2023


On 23/06/2023 16:54, trent shipley wrote:
> How do I drive a command line interface for a Python script to test that
> the CLI is working per design?

There are test frameworks for python but one of the easiest
ways for a CLI is to use file redirection

OS> python3 myprogram.py <testN_input.txt >testN_output.txt

testN_input.txt then contains all the input strings required
to run the testN scenario.
The results will be captured in testN_output.txt and can be
compared to the expected output (stored in, say, testN_results.txt)

If the files testN_results.txt and testN_output.txt are
identical then the test passes.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos





More information about the Tutor mailing list