Skip to content

Conversation

cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Aug 26, 2025

This sets up for having a test_io._support which contains the I/O mocks for sharing between multiple io module test files. Also starts a path for all the io module tests to live in a single module for simpler running rather than requiring knowledge of the list of io tests which lives in a comment in test_io.

Common test invocatoins (ex. python -m test test_io -uall -M8G and python -m test.test_io) run the same set of tests after this change as before.


I copied __init__.py and __main__.py from other python test sub directory instances; happy to tweak if needed.

It is possible to split out the Buffered I/O tests without moving test_io to be a module. In that case still will need a module where the common "mocks" live (My tentative plan is test.test_io._support). I think this sets up for more understandable structure to the io tests overall, but happy to explore the problem space if desired.

This sets up for having a test_io._support which contains the I/O mocks
for sharing between multiple `io` module test files. Also starts a path
for all the `io` module tests to live in a single module for simpler
running rather than requiring knowledge of the list of `io` tests which
lives in `test_io`.

Keeps `python -m test test_io -uall -M8g` and `python -m test.test_io` running the
same set of tests as before.
@AA-Turner
Copy link
Member

This sets up for having a test_io._support which contains the I/O mocks for sharing between multiple io module test files.

The usual pattern is test.test_support.{topic}_helper, isn't it? Can you elaborate on the proposed _support module?

@cmaloney
Copy link
Contributor Author

I was following what I saw in a couple instances (ex. test_string: https://github.com/python/cpython/blob/main/Lib/test/test_string/_support.py, test_zoneinfo: https://github.com/python/cpython/blob/main/Lib/test/test_zoneinfo/_support.py). There's also a couple of support.py (ex. https://github.com/python/cpython/blob/main/Lib/test/test_tkinter/support.py). No idea what is most common or being worked towards as layout.

The IO Mocks are only useful for testing the two io module implementations (_io C and _pyio Python) and have specific to io naming patterns that are currently required (ex. MockRawIO -> CMockRawIO, PyMockRawIO + load_tests injection https://github.com/python/cpython/blob/main/Lib/test/test_io.py#L5040-L5077). Things in test.support feel like they're useful for testing multiple Python modules which I don't think these mocks are.

@cmaloney
Copy link
Contributor Author

Another approach here would be to make a mock_io.py which mirrors https://github.com/python/cpython/blob/main/Lib/test/mock_socket.py, which would leave test_io.py in the current location (and not need a __main__.py + __init__.py).

Comment on lines 5 to 10
# * test_memoryio - tests BytesIO and StringIO
# * test_fileio - tests FileIO
# * test_file - tests the file interface
# * test_io - tests everything else in the io module
# * test_io.test_general - tests everything else in the io module
# * test_univnewlines - tests universal newline support
# * test_largefile - tests operations on a file greater than 2**32 bytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the modules here be moved into the new package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan is yes over time, just limiting scope of changes (and PRs) to pieces I'm actively working on changing (Currently Buffered I/O layer). test_bufio I plan to do as part of this overall issue (gh-138013). Not sure how much people rely on the names currently (ex. tracking performance over time by measuring test runtime). Unfortunately there are no benchmarks for CPython I/O in pyperformance currently (is part of my backlog to add).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests can and do move around, we don't make any guarantees here. Performance tests should use the pyperformance suite.

@AA-Turner
Copy link
Member

If only useful within test_io then a test_io._mock_io or similar seems appropriate, thanks for the explanation.

@cmaloney
Copy link
Contributor Author

Could this get a skip news tag? (Test-only change)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants