Fix crash when sys.stdin
is None
by emilburzo · Pull Request #7118 · pypa/pip (original) (raw)
Hi @emilburzo!
Thanks for the update. is_console_interactive
seems like a fine name to me. I think this is definitely testable.
I would add a helper function and two tests in tests/unit/test_utils.py
(probably at the bottom).
The function would take a monkeypatch argument and do something like monkeypatch.setattr(sys.stdin, 'isatty', Mock(return_value=True))
, this ensures that the behavior is consistent no matter if we're running locally or in CI.
The first test would call the helper function then make sure that is_console_interactive
returns True.
The second (maybe test_is_console_interactive_when_stdin_is_None
?) would call the helper function, then monkeypatch.setattr(sys, 'stdin', None)
, then check that is_console_interactive
returns False.
That ensures that we're always testing the situation that would succeed except for the other changes we make for the failure test cases - this will help a lot with the other change mentioned in #7042 later.