Skip to content

Commit d047a29

Browse files
Fix a test failure caused by an internal docutils open() call (#332)
docutils 0.22 introduced an RST stylesheet feature that must be able to open files during RST-to-HTML rendering. The original design of the `test_cli_explicit_format` test patched `pathlib.Path.open()` so it would always return the same open file instance...which was always closed on first use. This caused a failure when docutils tried to open `minimal.css`: ``` ValueError: I/O operation on closed file. ``` This change introduces a temporary input file to read from, rather than attempting to mock `pathlib.Path.open()`. Co-authored-by: Mike Fiedler <miketheman@gmail.com>
1 parent 9d94848 commit d047a29

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/test_cli.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ def test_cli_invalid_format():
4444
main(["no-file.invalid"])
4545

4646

47-
def test_cli_explicit_format(input_file):
47+
def test_cli_explicit_format(input_file, tmp_path):
4848
fmt = input_file.suffix.lstrip(".")
49-
with input_file.open() as fp, \
50-
mock.patch("pathlib.Path.open", return_value=fp), \
51-
mock.patch("builtins.print") as print_:
52-
main(["-f", fmt, "no-file.invalid"])
53-
print_.assert_called_once()
49+
50+
temp_input = tmp_path / "invalid.invalid"
51+
temp_input.write_text(input_file.read_text())
52+
53+
with mock.patch("builtins.print") as print_:
54+
main(["-f", fmt, str(temp_input)])
5455
(result,), _ = print_.call_args
5556

5657
with input_file.with_suffix(".html").open() as fp:

0 commit comments

Comments
 (0)