Skip to content

Conversation

kurtmckee
Copy link
Contributor

@kurtmckee kurtmckee commented Aug 20, 2025

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 more complex mocking strategy that documents and meets the current technical requirements.

When combined with #328, the full test suite will now pass.

Note

It may be worthwhile to consider using the pyfakefs plugin, and pytest's capsys, to simplify some of the mocking and patching used in the test suite.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Sep 23, 2025
https://build.opensuse.org/request/show/1306508
by user dgarcia + anag_factory
Fix the Staging:E with new python-docutils

- Skip broken test with latest docutils, gh#pypa/readme_renderer#332
@kurtmckee
Copy link
Contributor Author

Hello @miketheman, I hope you're well! I was wondering if you could take a look at this PR -- and a couple of others -- that address lint and test suite failures?

For example, this PR fixes new CI failures; #328 addresses lint failures; and both of these issues were found when CI ran on #327.

Thanks for your time, and have a great weekend!

@miketheman
Copy link
Member

Hey @kurtmckee ! Thanks for looking into it.

This definitely is an odd smell, but I think there might be a simpler solution here, by copying the input to a temp file, using builtin fixture tmp_path. Something like:

-def test_cli_explicit_format(input_file):
+def test_cli_explicit_format(input_file, tmp_path):
     fmt = input_file.suffix.lstrip(".")
-    with input_file.open() as fp, \
-            mock.patch("pathlib.Path.open", return_value=fp), \
-            mock.patch("builtins.print") as print_:
-        main(["-f", fmt, "no-file.invalid"])
+
+    temp_input = tmp_path / "no-file.invalid"
+    temp_input.write_text(input_file.read_text())
+
+    with mock.patch("builtins.print") as print_:
+        main(["-f", fmt, str(temp_input)])

What do you think?

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()`.
@kurtmckee kurtmckee force-pushed the fix-test-suite-failure branch from 1a6d24c to ebd43ed Compare October 7, 2025 23:02
@kurtmckee
Copy link
Contributor Author

Works for me! I had been under the impression that it was undesirable to write a temporary file so I tried to stick with that assumed goal. Much easier this way!

I've updated the PR to match your suggestion. Type annotation linting will fail; that's addressed in #328.

@miketheman miketheman mentioned this pull request Oct 9, 2025
@miketheman miketheman merged commit d047a29 into pypa:main Oct 9, 2025
9 checks passed
@miketheman
Copy link
Member

Thanks for working through this, @kurtmckee !

@kurtmckee kurtmckee deleted the fix-test-suite-failure branch October 10, 2025 13:41
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.

2 participants