Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68182
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Testing interactive code using raw_input |
| Date | 2014-03-11 10:39 +1100 |
| References | <531de147$0$29994$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8027.1394494787.18130.python-list@python.org> (permalink) |
Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes: > Does anyone have any good hints for testing interactive code that uses > raw_input, or input in Python 3? Are you testing the behaviour of the ‘input’ function? If not, then it is an external dependency; and, since you're not interested in testing its behaviour, you can contrive its behaviour to be exactly what you want: Mock the function during your unit test, and get it to produce whatever output you like. Mocking is a blunt instrument, but when the external dependency is problematic – and it seems like “access to an interactive terminal” is a problematic dependency – you should mock the dependency out for those tests where the dependency is external to what you want to test. -- \ “'Tis strange, — but true; for truth is always strange; / | `\ Stranger than fiction.” —“Lord” George Gordon Noel Byron, _Don | _o__) Juan_ | Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Testing interactive code using raw_input Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-10 15:59 +0000
Re: Testing interactive code using raw_input Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-03-10 16:05 +0000
Re:Testing interactive code using raw_input Dave Angel <davea@davea.name> - 2014-03-10 12:40 -0400
Re: Testing interactive code using raw_input Peter Otten <__peter__@web.de> - 2014-03-10 17:57 +0100
Re: Testing interactive code using raw_input Steven D'Aprano <steve@pearwood.info> - 2014-03-11 08:26 +0000
Re: Testing interactive code using raw_input Ethan Furman <ethan@stoneleaf.us> - 2014-03-10 09:53 -0700
Re: Testing interactive code using raw_input Ben Finney <ben+python@benfinney.id.au> - 2014-03-11 10:39 +1100
csiph-web