How can I simulate input to stdin for pyunit?

前端 未结 5 1010
清酒与你
清酒与你 2020-12-03 10:56

I\'m trying to test a function that takes input from stdin, which I\'m currently testing with something like this:

cat /usr/share/dict/words | .         


        
5条回答
  •  死守一世寂寞
    2020-12-03 11:30

    If you are using mock module (written by Michael Foord), in order to mock raw_input function you can use syntax like:

    @patch('src.main.raw_input', create=True, new=MagicMock(return_value='y'))
    def test_1(self):
        method_we_try_to_test();    # method or function that calls **raw_input**
    

提交回复
热议问题