capture: factor out _get_multicapture#6788
Conversation
src/_pytest/capture.py
Outdated
| sys.stderr.write(err) | ||
|
|
||
|
|
||
| def _get_multicapture(method: str) -> "MultiCapture": |
There was a problem hiding this comment.
TIOLI: Use Literal["fd", "sys", "no", "tee-sys"] instead of str.
There was a problem hiding this comment.
Well, here I took your advice that it should not be used when the API (even if internal IIUC) is going to change (when adding new methods).
But I would prefer the Literal also, I'm just confused.. :)
There was a problem hiding this comment.
Hehe :) Well up to now we discussed return types, but this is an input type. Input types should be as restrictive as possible to rule out illegal inputs.
This is assuming the function is not a validating function (whose purpose is to take out general inputs and check them). In this case the input is already validated by the --capture arg parsing (which has choices=["fd", "sys", "no", "tee-sys"]), so any other kind of input is a not supposed to reach here.
If you choose to make this a Literal, it would make sense to also change CaptureManager(method=...) to have this type already.
There was a problem hiding this comment.
Ok.
But it might become a validating / more flexible method (https://github.com/pytest-dev/pytest/pull/6671/files#diff-e4269384a671a462a4824e8b06d4644bR97-R121), where choices then however would need to be factored out likely. But until then I think it makes sense to use Literal here already.
663eaee to
71a6987
Compare
Ref: #6671 (comment)
TODO:
matchwithpytest.raises()#6753)