Skip to content

Restore sys.argv and sys.stdin after the command line tests - #291

Open
ptweezy wants to merge 1 commit into
pycompression:developfrom
ptweezy:test-cli-sys-state
Open

ptweezy wants to merge 1 commit into
pycompression:developfrom
ptweezy:test-cli-sys-state

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

The command line tests in tests/test_igzip.py assign sys.argv and sys.stdin directly, and pytest doesn't restore them between tests. test_compress_infile_out_file_prompt passes only because an earlier test leaves an exhausted sys.stdin behind. Run alone or with -k prompt, it fails:

OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

The tests now set both attributes with monkeypatch, and the prompt test gets an empty sys.stdin. In tests/test_gzip_compliance.py, TestCommandLine.test_decompress_infile_outfile now sets sys.argv with mock.patch.object(). The leaked sys.argv breaks no test today, but these tests now restore it too.

On develop, 5 of 40 random orders of tests/test_igzip.py (pytest-randomly seeds 1 to 40) fail. With this PR, none do.

This PR changes only tests, so it has no CHANGELOG entry.

Checklist

  • Pull request details were added to CHANGELOG.rst
  • Documentation was updated (if needed)

The command line tests assigned sys.argv and sys.stdin directly, and
pytest does not restore them between tests.
test_compress_infile_out_file_prompt passed only because an earlier
test left an exhausted sys.stdin behind, and it failed when run alone.
Set both with monkeypatch or mock.patch.object(), and give the prompt
test an empty sys.stdin.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant