From ff312137610681a4dbd07666287e9dd5ed9158ae Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Mon, 1 Sep 2025 15:52:34 -0700 Subject: [PATCH 1/3] gh-138013: Move I/O tests to test_io Centralize `io` tests into the `test_io` module so they are easier to find and work on. This will make it easier to split `test_general` which takes 30+ seconds in a debug build on my machine. This renames `test_bufio` to be `test_bufferedio` so that it matches the implementation file name (`bufferedio.c`). Validation performed: Tests are run in parallel after change: ```bash ./python.exe -m test test_io -uall,largefile,extralargefile -M12G -j8 ``` Docstring reformat in `test_io/__init__.py` looks reasonable: ```python >>> import test.test_io >>> help(test.test_io) ``` --- Lib/test/libregrtest/findtests.py | 1 + Lib/test/test_io/__init__.py | 23 +++++++++++++++++ .../test_bufferedio.py} | 0 Lib/test/{ => test_io}/test_file.py | 0 Lib/test/{ => test_io}/test_fileio.py | 0 Lib/test/test_io/test_general.py | 25 +++---------------- Lib/test/{ => test_io}/test_largefile.py | 0 Lib/test/{ => test_io}/test_memoryio.py | 0 Lib/test/{ => test_io}/test_univnewlines.py | 0 9 files changed, 28 insertions(+), 21 deletions(-) rename Lib/test/{test_bufio.py => test_io/test_bufferedio.py} (100%) rename Lib/test/{ => test_io}/test_file.py (100%) rename Lib/test/{ => test_io}/test_fileio.py (100%) rename Lib/test/{ => test_io}/test_largefile.py (100%) rename Lib/test/{ => test_io}/test_memoryio.py (100%) rename Lib/test/{ => test_io}/test_univnewlines.py (100%) diff --git a/Lib/test/libregrtest/findtests.py b/Lib/test/libregrtest/findtests.py index f01c1240774707..79afaf9083ae59 100644 --- a/Lib/test/libregrtest/findtests.py +++ b/Lib/test/libregrtest/findtests.py @@ -24,6 +24,7 @@ "test_future_stmt", "test_gdb", "test_inspect", + "test_io", "test_pydoc", "test_multiprocessing_fork", "test_multiprocessing_forkserver", diff --git a/Lib/test/test_io/__init__.py b/Lib/test/test_io/__init__.py index 4b16ecc31156a5..8430c7f6f3f985 100644 --- a/Lib/test/test_io/__init__.py +++ b/Lib/test/test_io/__init__.py @@ -1,3 +1,26 @@ +"""Tests for the io module and its implementations (_io and _pyio) + +Tests are split across multiple files inside `test_io` to increase +parallelism and focus on specific pieces implementation pieces. + +* test_io + * test_bufferedio - tests file buffering + * test_memoryio - tests BytesIO and StringIO + * test_fileio - tests FileIO + * test_file - tests the file interface + * 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 + (only enabled with -ulargefile) +* test_free_threading/test_io - tests thread safety of io objects + +.. attention:: + When writing tests for io, it's important to test both the C and Python + implementations. This is usually done by writing a base test that refers to + the type it is testing as an attribute. Then it provides custom subclasses to + test both implementations. This file has lots of examples. +""" + import os from test.support import load_package_tests diff --git a/Lib/test/test_bufio.py b/Lib/test/test_io/test_bufferedio.py similarity index 100% rename from Lib/test/test_bufio.py rename to Lib/test/test_io/test_bufferedio.py diff --git a/Lib/test/test_file.py b/Lib/test/test_io/test_file.py similarity index 100% rename from Lib/test/test_file.py rename to Lib/test/test_io/test_file.py diff --git a/Lib/test/test_fileio.py b/Lib/test/test_io/test_fileio.py similarity index 100% rename from Lib/test/test_fileio.py rename to Lib/test/test_io/test_fileio.py diff --git a/Lib/test/test_io/test_general.py b/Lib/test/test_io/test_general.py index a56a2c0157f764..b582aa1f952a74 100644 --- a/Lib/test/test_io/test_general.py +++ b/Lib/test/test_io/test_general.py @@ -1,24 +1,7 @@ -"""Unit tests for the io module.""" - -# Tests of io are scattered over the test suite: -# * test_bufio - tests file buffering -# * test_memoryio - tests BytesIO and StringIO -# * test_fileio - tests FileIO -# * test_file - tests the file interface -# * 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 -# (only enabled with -ulargefile) -# * test_free_threading/test_io - tests thread safety of io objects - -################################################################################ -# ATTENTION TEST WRITERS!!! -################################################################################ -# When writing tests for io, it's important to test both the C and Python -# implementations. This is usually done by writing a base test that refers to -# the type it is testing as an attribute. Then it provides custom subclasses to -# test both implementations. This file has lots of examples. -################################################################################ +"""General tests for the io module. + +New tests should go in more specific modules; see test_io/__init__.py +""" import abc import array diff --git a/Lib/test/test_largefile.py b/Lib/test/test_io/test_largefile.py similarity index 100% rename from Lib/test/test_largefile.py rename to Lib/test/test_io/test_largefile.py diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_io/test_memoryio.py similarity index 100% rename from Lib/test/test_memoryio.py rename to Lib/test/test_io/test_memoryio.py diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_io/test_univnewlines.py similarity index 100% rename from Lib/test/test_univnewlines.py rename to Lib/test/test_io/test_univnewlines.py From f4f150e5bbd25cc64b670427c4f8a45280b6176e Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Mon, 1 Sep 2025 16:30:28 -0700 Subject: [PATCH 2/3] fix typo --- Lib/test/test_io/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_io/__init__.py b/Lib/test/test_io/__init__.py index 8430c7f6f3f985..0db9c2ee8b890a 100644 --- a/Lib/test/test_io/__init__.py +++ b/Lib/test/test_io/__init__.py @@ -1,7 +1,7 @@ """Tests for the io module and its implementations (_io and _pyio) Tests are split across multiple files inside `test_io` to increase -parallelism and focus on specific pieces implementation pieces. +parallelism and focus on specific implementation pieces. * test_io * test_bufferedio - tests file buffering From b98448f879173618d7a4bba042127cbd7f8a37bd Mon Sep 17 00:00:00 2001 From: Cody Maloney Date: Tue, 2 Sep 2025 21:01:04 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Lib/test/test_io/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_io/__init__.py b/Lib/test/test_io/__init__.py index 0db9c2ee8b890a..c94fad3e779381 100644 --- a/Lib/test/test_io/__init__.py +++ b/Lib/test/test_io/__init__.py @@ -1,6 +1,6 @@ """Tests for the io module and its implementations (_io and _pyio) -Tests are split across multiple files inside `test_io` to increase +Tests are split across multiple files to increase parallelism and focus on specific implementation pieces. * test_io @@ -18,7 +18,7 @@ When writing tests for io, it's important to test both the C and Python implementations. This is usually done by writing a base test that refers to the type it is testing as an attribute. Then it provides custom subclasses to - test both implementations. This file has lots of examples. + test both implementations. This directory contains lots of examples. """ import os