I want to use stdin in a pytest test

前端 未结 2 1760
不思量自难忘°
不思量自难忘° 2021-02-12 12:15

The PyTest documentation states that stdin is redirected to null as no-one will want to do interactive testing in a batch test context. This is true, but interactive is not the

2条回答
  •  囚心锁ツ
    2021-02-12 13:01

    You can mock it:

    def test_method(monkeypatch):
        monkeypatch.setattr('sys.stdin', io.StringIO('my input'))
        # test code
    

提交回复
热议问题