Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test files into test subdirectories #108303

Closed
vstinner opened this issue Aug 22, 2023 · 18 comments
Closed

Move test files into test subdirectories #108303

vstinner opened this issue Aug 22, 2023 · 18 comments
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

vstinner commented Aug 22, 2023

Feature or enhancement

Proposal:

The Python test suite has around 166 files and sub-directories where the name is not clearly associated to a test. For example, it's not obvious to me which test uses talos-2019-0758.pem or coding20731.py.

When possible, I propose to move these files into sub-directories related to their test. Example:

  • create Lib/test/test_module/ sub-directory
  • move Lib/test/test_module.py to Lib/test/test_module/__init__.py
  • move good_getattr.py and bad_getattr*.py scripts to Lib/test/test_module/

Well, I created PR #108293 for this specific example.

Linked PRs

@vstinner vstinner added the type-feature A feature request or enhancement label Aug 22, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Aug 22, 2023
In Python 2.7, the file was used by Lib/test/test_sgmllib.py to test
Lib/sgmllib.py. The sgmllib module and its tests have been removed in
Python 3.0.
@vstinner
Copy link
Member Author

Files (161):

allsans.pem
ann_module2.py
ann_module3.py
ann_module4.py
ann_module5.py
ann_module6.py
ann_module7.py
ann_module8.py
ann_module.py
audiodata/
audiotests.py
audit-tests.py
autotest.py
badcert.pem
bad_coding2.py
bad_coding.py
badkey.pem
badsyntax_3131.py
badsyntax_future10.py
badsyntax_future3.py
badsyntax_future4.py
badsyntax_future5.py
badsyntax_future6.py
badsyntax_future7.py
badsyntax_future8.py
badsyntax_future9.py
badsyntax_pep3120.py
bisect_cmd.py*
capath/
cfgparser.1
cfgparser.2
cfgparser.3
cjkencodings/
clinic.test.c
cmath_testcases.txt
coding20731.py
crashers/
curses_tests.py*
data/
dataclass_module_1.py
dataclass_module_1_str.py
dataclass_module_2.py
dataclass_module_2_str.py
dataclass_textanno.py
datetimetester.py
decimaltestdata/
dis_module.py
double_const.py
dtracedata/
empty.vbs
encoded_modules/
exception_hierarchy.txt
ffdh3072.pem
final_a.py
final_b.py
floating_points.txt
fork_wait.py
formatfloat_testcases.txt
future_test1.py
future_test2.py
gdb_sample.py
idnsans.pem
ieee754.txt
imp_dummy.py
__init__.py
inspect_fodder2.py
inspect_fodder.py
inspect_stock_annotations.py
inspect_stringized_annotations_2.py
inspect_stringized_annotations.py
keycert2.pem
keycert3.pem
keycert4.pem
keycertecc.pem
keycert.passwd.pem
keycert.pem
leakers/
levenshtein_examples.json
libregrtest/
list_tests.py
lock_tests.py
__main__.py
make_ssl_certs.py
mapping_tests.py
math_testcases.txt
memory_watchdog.py
mime.types
mock_socket.py
mod_generics_cache.py
mp_fork_bomb.py
mp_preload.py
multibytecodec_support.py
nokia.pem
nosan.pem
nullbytecert.pem
nullcert.pem
pickletester.py
profilee.py
pstats.pck
pycacert.pem
__pycache__/
pycakey.pem
pyclbr_input.py
pydocfodder.py
pydoc_mod.py
pythoninfo.py
randv2_32.pck
randv2_64.pck
randv3.pck
recursion.tar
regrtest.py*
relimport.py
reperf.py
re_tests.py*
revocation.crl
sample_doctest.py
secp384r1.pem
selfsigned_pythontestdotnet.pem
seq_tests.py
setup_testcppext.py
setuptools-67.6.1-py3-none-any.whl
shadowed_super.py
signalinterproctester.py
smtpd.py*
sortperf.py
ssl_cert.pem
ssl_key.passwd.pem
ssl_key.pem
ssl_servers.py
ssltests.py
string_tests.py
subprocessdata/
support/
talos-2019-0758.pem
testcodec.py
_testcppext.cpp
test_difflib_expect.html
test_doctest2.txt
test_doctest3.txt
test_doctest4.txt
test_doctest.txt
testtar.tar
testtar.tar.xz
tf_inherit_check.py
time_hashlib.py
tkinterdata/
tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt
tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt
tokenize_tests.txt
tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt
tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
tracedmodules/
_typed_dict_helper.py
typinganndata/
wheel-0.40.0-py3-none-any.whl
win_console_handler.py
xmltestdata/
xmltests.py
zip_cp437_header.zip
zipdir.zip
ziptestdata/

@vstinner
Copy link
Member Author

The alternative is to have a "data" directory, so a different directory name:

  • audiodata/
  • decimaltestdata/
  • dtracedata/
  • subprocessdata/
  • tkinterdata/
  • typinganndata/
  • xmltestdata/
  • ziptestdata/

@vstinner
Copy link
Member Author

Existing tests as a sub-directory (proposed solution):

  • test_asyncio/
  • test_capi/
  • test_ctypes/
  • test_email/
  • test_import/
  • test_importlib/
  • test_json/
  • test_lib2to3/
  • test_module/
  • test_peg_generator/
  • test_sqlite3/
  • test_tkinter/
  • test_tomllib/
  • test_tools/
  • test_ttk/
  • test_unittest/
  • test_warnings/
  • test_zipfile/
  • test_zoneinfo/

@terryjreedy
Copy link
Member

I have also noticed and wondered about the melange of misc files. I like packaging the test code and data together in one directory, as in your 'module' example, especially given that we already have test_xyz directories.

vstinner added a commit that referenced this issue Aug 22, 2023
In Python 2.7, the file was used by Lib/test/test_sgmllib.py to test
Lib/sgmllib.py. The sgmllib module and its tests have been removed in
Python 3.0.
vstinner added a commit to vstinner/cpython that referenced this issue Aug 22, 2023
* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.
@vstinner
Copy link
Member Author

I created PR #108299 for test_crashers.

vstinner added a commit that referenced this issue Aug 22, 2023
* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 22, 2023
…8325)

* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.
(cherry picked from commit 21dda09)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit to vstinner/cpython that referenced this issue Aug 22, 2023
* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.

(cherry picked from commit 21dda09)
@AlexWaygood AlexWaygood added the tests Tests in the Lib/test dir label Aug 22, 2023
Yhg1s pushed a commit that referenced this issue Aug 22, 2023
…#108328)

gh-108303: Add Lib/test/test_cppext/ sub-directory (GH-108325)

* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.
(cherry picked from commit 21dda09)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this issue Aug 23, 2023
…108336)

gh-108303: Add Lib/test/test_cppext/ sub-directory (#108325)

* Move test_cppext to its own directory
* Rename setup_testcppext.py to setup.py
* Rename _testcppext.cpp to extension.cpp
* The source (extension.cpp) is now also copied by the test.

(cherry picked from commit 21dda09)
sobolevn added a commit to sobolevn/cpython that referenced this issue Aug 23, 2023
@serhiy-storchaka
Copy link
Member

What with data files used in several different tests?

@vstinner
Copy link
Member Author

What with data files used in several different tests?

For this case, I suggest to keep the current trend of having a "data/" directory, such as audiodata/. I don't think that duplicating files to "isolate" tests is worth it.

The problem with these "data" directories is that when a test file is no longer needed, it's more likely to be forgotten.

vstinner added a commit to vstinner/cpython that referenced this issue Sep 6, 2023
Move test_dataclasses.py and its "dataclass_*.py" modules into the
new Lib/test/test_dataclasses/ subdirectory.
vstinner added a commit to vstinner/cpython that referenced this issue Sep 6, 2023
Move test_doctest.py and test_doctest2.py the following files to
a new Lib/test/test_dataclasses/ directory. Move also data files:

* doctest*.py
* sample_doctest*.py
* test_doctest*.txt

Replace test with test.test_doctest in
Lib/test/test_doctest/test_doctest.py.
vstinner added a commit that referenced this issue Sep 6, 2023
Move test_dataclasses.py and its "dataclass_*.py" modules into the
new Lib/test/test_dataclasses/ subdirectory.
@vstinner
Copy link
Member Author

I close the issue. While it's not 100% done, remaining files can reuse this closed issue, or another issue can be created. This issue already has a long list of pull requests and a long history.

Thanks to everybody who helped cleaning Lib/test/, reviewers, and especially @sobolevn who wrote many changes!

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 18, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 18, 2024
sobolevn added a commit that referenced this issue Feb 18, 2024
…114687) (#115626)

gh-108303: Move `Lib/test/sortperf.py` to `Tools/scripts` (GH-114687)
(cherry picked from commit f9154f8)

Co-authored-by: Nikita Sobolev <[email protected]>
sobolevn added a commit that referenced this issue Feb 18, 2024
…114687) (#115625)

gh-108303: Move `Lib/test/sortperf.py` to `Tools/scripts` (GH-114687)
(cherry picked from commit f9154f8)

Co-authored-by: Nikita Sobolev <[email protected]>
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Update test_logging.py and test_smtplib.py.
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

6 participants