Commit Graph

118847 Commits

Author SHA1 Message Date
Victor Stinner de5f8f7d13
gh-109276: libregrtest: use separated file for JSON (#109277)
libregrtest now uses a separated file descriptor to write test result
as JSON.  Previously, if a test wrote debug messages late around the
JSON, the main test process failed to parse JSON.

Rename TestResult.write_json() to TestResult.write_json_into().

worker_process() no longer writes an empty line at the end. There is
no need to separate test process output from the JSON output anymore,
since JSON is now written into a separated file descriptor.

create_worker_process() now always spawn the process with
close_fds=True.
2023-09-11 19:33:42 +02:00
Nikita Sobolev baa6dc8e38
gh-90805: Make sure test_functools works with and without _functoolsmodule (GH-108644) 2023-09-11 19:13:37 +03:00
Hugo van Kemenade 57b6205523
gh-109190: What's New in 3.12: Add subheadings to removals for easy linking (#109159)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2023-09-11 19:06:16 +03:00
Victor Stinner 517cd82ea7
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
Fix _thread.start_new_thread() race condition. If a thread is created
during Python finalization, the newly spawned thread now exits
immediately instead of trying to access freed memory and lead to a
crash.

thread_run() calls PyEval_AcquireThread() which checks if the thread
must exit. The problem was that tstate was dereferenced earlier in
_PyThreadState_Bind() which leads to a crash most of the time.

Move _PyThreadState_CheckConsistency() from thread_run() to
_PyThreadState_Bind().
2023-09-11 17:27:03 +02:00
Serhiy Storchaka c0f488b88f
gh-109182: Fix and improve tests for gh-108654 (GH-109189) 2023-09-11 17:50:33 +03:00
Mark Shannon 4a69301ea4
GH-108976. Keep monitoring data structures valid during de-optimization during callback. (GH-109131) 2023-09-11 14:37:09 +01:00
Serhiy Storchaka 60b8341d07
Better integration of doctest and unittest in test_ctypes.test_objects (GH-108922)
Better integration of docrtest and unittest in test_ctypes.test_objects
2023-09-11 14:05:30 +03:00
Serhiy Storchaka 0abc935086
Test DocTestFinder directly instead of calling support.run_doctest() (GH-108917) 2023-09-11 14:03:30 +03:00
Victor Stinner c439f6a72d
gh-109162: libregrtest: move code around (#109253)
* Move Regrtest.display_header() to utils.py.
* Move cleanup_temp_dir() to utils.py.
* Move list_cases() to findtests.py.
2023-09-11 08:52:03 +00:00
Victor Stinner a9b1f84790
gh-107219: Fix concurrent.futures terminate_broken() (#109244)
Fix a race condition in concurrent.futures. When a process in the
process pool was terminated abruptly (while the future was running or
pending), close the connection write end. If the call queue is
blocked on sending bytes to a worker process, closing the connection
write end interrupts the send, so the queue can be closed.

Changes:

* _ExecutorManagerThread.terminate_broken() now closes
  call_queue._writer.
* multiprocessing PipeConnection.close() now interrupts
  WaitForMultipleObjects() in _send_bytes() by cancelling the
  overlapped operation.
2023-09-11 08:11:31 +00:00
Victor Stinner 3b2ecbc127
GH-108614: Increase importlib MAGIC for RESUME_CHECK instruction (#109247) 2023-09-11 09:34:04 +02:00
Victor Stinner 7aa8fcc8eb
gh-109162: libregrtest: use relative imports (#109250)
libregrtest.__init__ no longer exposes any symbol, so
"python -m test.libregrtest.worker" imports less modules.
2023-09-11 07:02:35 +00:00
Victor Stinner 0c139b5f2f
gh-109162: libregrtest: rename runtest_mp.py to run_workers.py (#109248)
* Rename runtest_mp.py to run_workers.py
* Move exit_timeout() and temp_cwd() context managers from
  Regrtest.main() to Regrtest.run_tests(). Actions like --list-tests
  or --list-cases don't need these protections.
* Regrtest: remove selected and tests attributes. Pass 'selected' to
  list_tests(), list_cases() and run_tests(). display_result() now
  expects a TestTuple, instead of TestList.
* Rename setup_tests() to setup_process() and rename setup_support()
  to setup_tests().
* Move _adjust_resource_limits() to utils and rename it to
  adjust_rlimit_nofile().
* Move replace_stdout() to utils.
* Fix RunTests.verbose type: it's an int.
2023-09-11 03:27:37 +00:00
Victor Stinner 0b6b05391b
gh-109162: libregrtest: fix Logger (#109246)
* Pass results, quiet and pgo to Logger constructor.
* Move display_progress() method from Regrtest to Logger.
* No longer pass Regrtest to RunWorkers, but logger and results.
2023-09-11 01:46:26 +00:00
Victor Stinner 1ec45378e9
gh-109162: libregrtest: add single.py and result.py (#109243)
* Add single.py and result.py files.
* Rename runtest.py to runtests.py.
* Move run_single_test() function and its helper functions to
  single.py.
* Move remove_testfn(), abs_module_name() and normalize_test_name()
  to utils.py.
* Move setup_support() to setup.py.
* Move type hints like TestName to utils.py.
* Rename runtest.py to runtests.py.
2023-09-11 00:07:18 +00:00
Victor Stinner a939b65aa6
gh-109162: libregrtest: add worker.py (#109229)
Add new worker.py file:

* Move create_worker_process() and worker_process() to this file.
* Add main() function to worker.py. create_worker_process() now
  runs the command: "python -m test.libregrtest.worker JSON".
* create_worker_process() now starts the worker process in the
  current working directory. Regrtest now gets the absolute path of
  the reflog.txt filename: -R command line option filename.
* Remove --worker-json command line option.
  Remove test_regrtest.test_worker_json().

Related changes:

* Add write_json() and from_json() methods to TestResult.
* Rename select_temp_dir() to get_temp_dir() and move it to utils.
* Rename make_temp_dir() to get_work_dir() and move it to utils.
  It no longer calls os.makedirs(): Regrtest.main() now calls it.
* Move fix_umask() to utils. The function is now called by
  setup_tests().
* Move StrPath to utils.
* Add exit_timeout() context manager to utils.
* RunTests: Replace junit_filename (StrPath) with use_junit (bool).
2023-09-11 01:11:22 +02:00
Victor Stinner e55aab9578
gh-109230: test_pyexpat no longer depends on the current directory (#109233)
Fix test_pyexpat.test_exception(): it can now be run from a directory
different than Python source code directory. Before, the test failed
in this case.

Skip the test if Modules/pyexpat.c source is not available. Skip also
the test on Python implementations other than CPython.
2023-09-10 22:16:59 +00:00
Victor Stinner cbb3a6f8ad
gh-109237: Fix test_site for non-ASCII working directory (#109238)
Fix test_site.test_underpth_basic() when the working directory
contains at least one non-ASCII character: encode the "._pth" file to
UTF-8 and enable the UTF-8 Mode to use UTF-8 for the child process
stdout.
2023-09-10 22:04:35 +00:00
Serhiy Storchaka d6892c2b92
gh-50644: Forbid pickling of codecs streams (GH-109180)
Attempts to pickle or create a shallow or deep copy of codecs streams
now raise a TypeError.

Previously, copying failed with a RecursionError, while pickling
produced wrong results that eventually caused unpickling to fail with
a RecursionError.
2023-09-10 20:06:09 +03:00
Victor Stinner 71b6e2602c
gh-109054: Don't use libatomic on cross-compilation (#109211)
configure no longer uses libatomic by default when Python is
cross-compiled. The LIBATOMIC variable can be set manually in this
case:

    ./configure LIBATOMIC="-latomic" (...)
2023-09-10 18:21:13 +02:00
云line 4297499696
gh-109207: Fix SystemError when printing symtable entry object. (GH-109225) 2023-09-10 15:04:24 +03:00
Delgan 2dd6a86c4e
Fix "FSTRING_MIDDLE" typo in py312 "What's New" (#109222) 2023-09-10 10:55:56 +00:00
Pieter Eendebak 85a5d3dbe1
gh-93627: Align Python implementation of pickle with C implementation of pickle (GH-103035)
If a method like __reduce_ex_ or __reduce__ is set to None, a TypeError is raised.
2023-09-10 10:06:08 +03:00
Serhiy Storchaka 92578919a6
gh-109174: Add support of SimpleNamespace in copy.replace() (GH-109175) 2023-09-10 08:09:25 +03:00
Victor Stinner 0eab2427b1
gh-109162: libregrtest: add Logger class (#109212)
* Add Logger class in a new logger.py file.
* Move Regrtest attributes to Logger:

  * start_time
  * test_count_text
  * test_count_width
  * win_load_tracker

* Move Regrtest method to Logger:

  * log()
  * getloadavg(): rename to get_load_avg()
  * set_tests()

* Add methods to the Logger class:

  * start_load_tracker()
  * stop_load_tracker()
2023-09-10 03:04:26 +00:00
Victor Stinner db5bfe91f8
gh-109162: libregrtest: add TestResults class (#109208)
* Add TestResults class.
* Move Regrtest methods to TestResults:

  * accumulate_result(): now takes a RunTests parameter
  * get_executed()
  * no_tests_run()

* Add methods to TestResults:

  * add_junit()
  * display_result()
  * display_summary()
  * need_rerun()
  * prepare_rerun()
  * write_junit()

* Rename 'need_rerun' attribute to 'bad_results'.
* Rename 'total_stats' attribute to 'stats'.
2023-09-10 02:30:43 +00:00
Victor Stinner a341750078
gh-109162: Refactor libregrtest.Regrtest (#109206)
* Add type hint types: TestName, StrPath, StrJSON.
* Add attributes to Regrtest:

  * cmdline_args
  * coverage
  * coverage_dir
  * fail_rerun
  * next_single_filename
  * print_slowest
  * tmp_dir
  * want_rerun
  * want_run_leaks

* Remove Regrtest.ns attribute.
* Rename Regrtest methods:

  * cleanup() => cleanup_temp_dir()
  * create_temp_dir() => make_temp_dir()
  * set_temp_dir() => select_temp_dir()

* Convert Regrtest methods to static methods:

  * cleanup_temp_dir()
  * display_header()
  * fix_umask()
  * get_rerun_match_tests()
  * list_tests()
  * make_temp_dir()
  * select_temp_dir()

* Remove display_sanitizers() method: move code into
  display_header().
* Rename 'test_cwd' variable to 'work_dir'.
2023-09-10 03:07:05 +02:00
Victor Stinner 0553fdfe30
gh-109162: Refactor libregrtest.runtest_mp (#109205)
* Add attributes to Regrtest and RunTests:

  * fail_env_changed
  * num_workers

* Rename MultiprocessTestRunner to RunWorkers. Add num_workers
  parameters to RunWorkers constructor. Remove RunWorkers.ns
  attribute.
* Rename TestWorkerProcess to WorkerThread.
* get_running() now returns a string like: "running (...): ...".
* Regrtest.action_run_tests() now selects the number of worker
  processes, instead of the command line parser.
2023-09-10 00:24:38 +00:00
Victor Stinner 0c0f254230
gh-109162: libregrtest: remove WorkerJob class (#109204)
* Add attributes to Regrtest and RunTests:

  * gc_threshold
  * memory_limit
  * python_cmd
  * use_resources

* Remove WorkerJob class. Add as_json() and from_json() methods to
  RunTests. A worker process now only uses RunTests for all
  parameters.
* Add tests on support.set_memlimit() in test_support. Create
  _parse_memlimit() and also adds tests on it.
* Remove 'ns' parameter from runtest.py.
2023-09-10 01:41:21 +02:00
Victor Stinner 24fa8f2046
gh-109162: libregrtest: fix _decode_worker_job() (#109202)
Decode also HuntRefleak() object inside the RunTests object.

Add an unit test on huntrleaks with multiprocessing (-R -jN).
2023-09-10 00:51:24 +02:00
Raymond Hettinger d3ed9921cd
Improve the sieve() recipe in the itertools docs (gh-109199)
Lazier sieve
2023-09-09 17:50:04 -05:00
Raymond Hettinger 75cd86599b
Fix an ironic typo in a code comment. (gh-109186) 2023-09-09 10:21:42 -05:00
Victor Stinner e21c89f984
gh-109162: Refactor libregrtest.RunTests (#109177)
* Rename dash_R() runtest_refleak(). The function now gets
  huntrleaks and quiet arguments, instead of 'ns' argument.
* Add attributes to Regrtest and RunTests:

  * verbose
  * quiet
  * huntrleaks
  * test_dir

* Add HuntRefleak class.
2023-09-09 09:18:14 +00:00
Serhiy Storchaka b4131a13cb
gh-109050: Remove remaining tests for legacy Unicode C API (GH-109068) 2023-09-09 05:44:46 +00:00
Jelle Zijlstra 17f994174d
gh-109118: Fix runtime crash when NameError happens in PEP 695 function (#109123) 2023-09-09 02:49:20 +00:00
Victor Stinner e9e2ca7a7b
gh-109162: Refactor libregrtest.runtest (#109172)
* Rename runtest() to run_single_test().
* Pass runtests to run_single_test().
* Add type annotation to Regrtest attributes. Add missing attributes
  to Namespace.
* Add attributes to Regrtest and RunTests:

  * fail_fast
  * ignore_tests
  * match_tests
  * output_on_failure
  * pgo
  * pgo_extended
  * timeout

* Get pgo from 'runtests', rather than from 'ns'.
* Remove WorkerJob.match_tests.
* setup_support() now gets pgo_extended from runtests.
* save_env(): change parameter order, pass test_name first.
* Add setup_test_dir() function.
* Pass runtests to setup_tests().
2023-09-09 01:37:48 +00:00
Tian Gao 057bc72490
gh-109052: Use the base opcode when comparing code objects (gh-109107) 2023-09-09 10:24:49 +09:00
Victor Stinner a56c928756
gh-109162: Refactor libregrtest WorkerJob (#109171)
* Rename --worker-args command line option to --worker-json.
* Rename _parse_worker_args() to _parse_worker_json().
* WorkerJob:

  * Add runtests attribute
  * Remove test_name and rerun attribute

* Rename run_test_in_subprocess() to create_worker_process().
* Rename run_tests_worker() to worker_process().
* create_worker_process() uses json.dump(): write directly JSON to
  stdout.
* Convert MultiprocessResult to a frozen dataclass.
* Rename RunTests.match_tests to RunTests.match_tests_dict.
2023-09-09 01:03:39 +00:00
Victor Stinner 489ca0acf0
gh-109162: Refactor Regrtest.action_run_tests() (#109170)
Refator Regrtest class:

* Rename finalize() finalize_tests().
* Pass tracer to run_test() and finalize_tests(). Remove Regrtest.tracer.
* run_test() does less things: move code to its caller.
2023-09-09 00:30:28 +00:00
Victor Stinner 2fafc3d5c6
gh-108996: Skip broken test_msvcrt for now (#109169) 2023-09-08 23:56:53 +00:00
Victor Stinner ac8409b38b
gh-109162: Regrtest copies 'ns' attributes (#109168)
* Regrtest.__init__() now copies 'ns' namespace attributes to
  Regrtest attributes. Regrtest match_tests and ignore_tests
  attributes have type FilterTuple (tuple), instead of a list.
* Add RunTests.copy(). Regrtest._rerun_failed_tests() now uses
  RunTests.copy().
* Replace Regrtest.all_tests (list) with Regrtest.first_runtests
  (RunTests).
* Make random_seed maximum 10x larger (9 digits, instead of 8).
2023-09-08 23:48:54 +00:00
Victor Stinner 5b7303e265
gh-109162: Refactor Regrtest.main() (#109163)
* main() now calls _parse_args() and pass 'ns' to Regrtest
  constructor.  Remove kwargs argument from Regrtest.main().
* _parse_args() checks ns.huntrleaks.
* set_temp_dir() is now responsible to call expanduser().
* Regrtest.main() sets self.tests earlier.
* Add TestTuple and TestList types.
* Rename MatchTests to FilterTuple and rename MatchTestsDict
  to FilterTestDict.
* TestResult.get_rerun_match_tests() return type
  is now FilterTuple: return a tuple instead of a list.
  RunTests.tests type becomes TestTuple.
2023-09-08 22:41:26 +00:00
AN Long bcb2ab5ef8
gh-108996: add tests for msvcrt (#109004)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2023-09-08 18:38:38 -04:00
Victor Stinner 1f7e42131d
gh-109054: configure checks if libatomic is needed (#109101)
Fix building the _testcapi extension on Linux AArch64 which requires
linking to libatomic when <cpython/pyatomic.h> is used: the
_Py_atomic_or_uint64() function requires libatomic
__atomic_fetch_or_8() on this platform.

The configure script now checks if linking to libatomic is needed and
generates a new LIBATOMIC variable used to build the _testcapi
extension.

Building the _testcapi extension now uses the LIBATOMIC variable in
its LDFLAGS, since Modules/_testcapi/pyatomic.c uses
<cpython/pyatomic.h>.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-09-08 23:14:33 +02:00
Alex Waygood 697c9dcf8f
gh-108455: peg_generator: enable mypy's `--warn-unreachable` setting and `redundant-expr` error code (#109160) 2023-09-08 22:05:40 +01:00
Victor Stinner 15d659f929
gh-91960: FreeBSD Cirrus CI runs configure separately (#109127)
Run configure and make in separated steps to have more readable logs.
2023-09-08 22:06:34 +02:00
Pablo Galindo Salgado 5bda2f637e
gh-109114: Relax the check for invalid lambdas inside f-strings to avoid false positives (#109121) 2023-09-08 17:00:23 +00:00
Serhiy Storchaka 87a7faf6b6
Check the result of PySet_Contains() for error in Python/symtable.c (GH-109146) 2023-09-08 19:57:41 +03:00
Mark Shannon 501f2dc527
GH-108614: Unbreak emscripten build (GH-109132) 2023-09-08 17:54:45 +01:00
Kumar Aditya ccd48623d4
GH-109067: fix randomly failing `test_async_gen_asyncio_gc_aclose_09` test (#109142)
Use `asyncio.sleep(0)` instead of short sleeps.
2023-09-08 16:27:58 +00:00