def test_win_at_run_cmd_line(mock_raw_input, capsys): random.seed(7) # secret is now 'ate' mock_raw_input.side_effect = [ 'apt', 'ape', 'ate', ] run_cmd_line() out, err = capsys.readouterr() assert 'you won' in out assert 'FAIL' not in out assert not err
def test_fail_at_run_cmd_line(mock_raw_input, capsys): random.seed(7) # secret is now 'ate' mock_raw_input.side_effect = [ 'apt', 'ape', ] with pytest.raises(StopIteration): run_cmd_line() out, err = capsys.readouterr() assert out == dedent('''\ Take a guess> 1 Take a guess> 2 Take a guess> ''') assert not err