Skip to content

Commit

Permalink
improve io mocking (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored Oct 11, 2024
1 parent 308c3a1 commit ba6e199
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- Inherited members are now hidden by default if the base class is not part of the documentation.
Please make yourself heard in https://github.com/mitmproxy/pdoc/issues/715 if you relied on the old behavior.
([#748](https://github.com/mitmproxy/pdoc/pull/748), @mhils)
- Improve mocking of `sys.stdin`, `sys.stdout`, and `sys.stderr` to fix runtime errors with some packages.
([#751](https://github.com/mitmproxy/pdoc/pull/751), @mhils)

## 2024-09-11: pdoc 14.7.0

Expand Down
6 changes: 3 additions & 3 deletions pdoc/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def mock_some_common_side_effects():
with (
patch("subprocess.Popen", new=_PdocDefusedPopen),
patch("os.startfile", new=_noop, create=True),
patch("sys.stdout", new=io.StringIO()),
patch("sys.stderr", new=io.StringIO()),
patch("sys.stdin", new=io.StringIO()),
patch("sys.stdout", new=io.TextIOWrapper(io.BytesIO())),
patch("sys.stderr", new=io.TextIOWrapper(io.BytesIO())),
patch("sys.stdin", new=io.TextIOWrapper(io.BytesIO())),
):
yield

Expand Down
9 changes: 9 additions & 0 deletions test/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from pdoc.extract import invalidate_caches
from pdoc.extract import mock_some_common_side_effects
from pdoc.extract import module_mtime
from pdoc.extract import parse_spec
from pdoc.extract import walk_specs
Expand Down Expand Up @@ -137,3 +138,11 @@ def raise_(*_):
monkeypatch.setattr(importlib, "reload", raise_)
with pytest.warns(UserWarning, match="Error reloading"):
invalidate_caches("pdoc.render_helpers")


def test_mock_sideeffects():
"""https://github.com/mitmproxy/pdoc/issues/745"""
with mock_some_common_side_effects():
import sys

sys.stdout.reconfigure(encoding="utf-8")

0 comments on commit ba6e199

Please sign in to comment.