Replies: 1 comment
|
Hi @danizen This is expected: pytest's captured
For code whose behavior intentionally changes when connected to a TTY, I would make that dependency injectable and test it with a small fake: import io
class FakeTTY(io.StringIO):
def isatty(self):
return True
def test_progress():
stream = FakeTTY()
show_progress(stream=stream)
assert "." in stream.getvalue()Alternatively, monkeypatch the particular If you genuinely need to test OS-level terminal behavior rather than your application's decision logic, use a pseudo-terminal ( Please mark this answer as accepted if it helped, thank you. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I've written a class to enhance the progress module providing my own "ChunkedSpinner" and "DotCounter". To properly test these, I should make sure they are printing respectively a spinning character or a dot every 50 calls to report progress - this is the point, to make sure that progress reporting doesn't make everything slower.
However, the progress module uses the isatty call to prevent output, and I'm wondering how that will play with capsys. For now, I am just testing that my code doesn't blow up and that the count of progression remains the same even with the chunking. Any suggestions?
All reactions