GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — Tests: error "tests may fail, unable to create temporary directory (...): [WinError 3] The system cannot find the path specified" on Windows · Issue #146202 · python/cpython Closed Labels OS-windowstestsTests in the Lib/test dirTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionWindows CI failure:
|
| Area | Description | Severity |
|---|---|---|
| CI pipeline stability | All Windows builds fail after test_itertools runs |
High |
| Test isolation | Subsequent tests inherit corrupted filesystem state | High |
| Unicode correctness | Non-ASCII filenames silently corrupted on Windows | Medium |
| Triage cost | Unrelated failures obscure the root cause | Medium |
| Local Windows dev | Developers running the full suite locally may be affected | Low |
Lib/test/test_itertools.py — primary location of the encoding issue and missing cleanupLib/test/support/os_helper.py — secondary impact point (temp_dir context manager)sys.getfilesystemencoding() docs: https://docs.python.org/3/library/sys.html#sys.getfilesystemencodingos.fsencode() docs: https://docs.python.org/3/library/os.html#os.fsencodeAzure DevOps build log:
https://dev.azure.com/Python/cpython/_build/results?buildId=168864&view=logs&j=c8a71634-e5ec-54a0-3958-760f4148b765&t=ddcdae4e-111a-5c2a-2289-6b784c553924
Extract of logs:
PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --junit-xml="D:\a\1\b\test-results.xml" --tempdir="D:\a\1\b\test"
D:\a\1\s>"D:\a\1\s\PCbuild\amd64\python.exe" -m test --fast-ci -uall -u-cpu -rwW --slowest --timeout 1200 -j0 --junit-xml D:\a\1\b\test-results.xml --tempdir D:\a\1\b\test
+ 'D:\a\1\s\PCbuild\amd64\python.exe' -u -W error -bb -E -m test --fast-ci -uall -u-cpu -rwW --slowest --timeout 1200 -j0 --junit-xml 'D:\a\1\b\test-results.xml' --tempdir 'D:\a\1\b\test' --dont-add-python-opts
== CPython 3.15.0a7+ (remotes/origin/52c01864c4778a351e5aa3584e86ed6fd212a5a4:52c01864c, Mar 19 2026, ) [MSC v.1944 64 bit (AMD64)]
== Windows-2022Server-10.0.20348-SP0 little-endian
== Python build: release with_assert
== cwd: D:\a\1\b\test\test_python_worker_2896æ
== CPU count: 2
== encodings: locale=cp1252 FS=utf-8
== resources: all,-cpu
Using random seed: 1027629067
0:00:00 Run 501 tests in parallel using 4 worker processes (timeout: 20 min, worker timeout: 25 min)
0:00:00 [ 1/501] test.test_io.test_file passed
0:00:00 [ 2/501] test_select passed
0:00:01 [ 3/501] test_type_comments passed
0:00:02 [ 4/501/1] test_range failed (env changed)
tests may fail, unable to create temporary directory 'D:\\a\\1\\s\\build\\test_python_4940æ': [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_4940æ'
Traceback (most recent call last):
File "D:\a\1\s\Lib\test\support\os_helper.py", line 524, in temp_dir
os.mkdir(path)
~~~~~~~~^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_4940æ'
Stack (most recent call last):
File "<frozen runpy>", line 196, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 138, in <module>
main()
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 133, in main
with os_helper.temp_cwd(work_dir, quiet=True):
File "D:\a\1\s\Lib\contextlib.py", line 141, in __enter__
return next(self.gen)
File "D:\a\1\s\Lib\test\support\os_helper.py", line 597, in temp_cwd
with temp_dir(path=name, quiet=quiet) as temp_path:
tests may fail, unable to change the current working directory to 'D:\\a\\1\\s\\build\\test_python_4940æ': [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_4940æ'
Traceback (most recent call last):
File "D:\a\1\s\Lib\test\support\os_helper.py", line 563, in change_cwd
os.chdir(os.path.realpath(path))
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_4940æ'
Stack (most recent call last):
File "<frozen runpy>", line 196, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 138, in <module>
main()
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 133, in main
with os_helper.temp_cwd(work_dir, quiet=True):
File "D:\a\1\s\Lib\contextlib.py", line 141, in __enter__
return next(self.gen)
File "D:\a\1\s\Lib\test\support\os_helper.py", line 598, in temp_cwd
with change_cwd(temp_path, quiet=quiet) as cwd_dir:
test_attributes (test.test_range.RangeTest.test_attributes) ... ok
test_comparison (test.test_range.RangeTest.test_comparison) ... ok
test_contains (test.test_range.RangeTest.test_contains) ... ok
test_count (test.test_range.RangeTest.test_count) ... ok
test_empty (test.test_range.RangeTest.test_empty) ... ok
test_exhausted_iterator_pickling (test.test_range.RangeTest.test_exhausted_iterator_pickling) ... ok
test_index (test.test_range.RangeTest.test_index) ... ok
test_invalid_invocation (test.test_range.RangeTest.test_invalid_invocation) ... ok
test_issue11845 (test.test_range.RangeTest.test_issue11845) ... ok
test_iterator_invalid_setstate (test.test_range.RangeTest.test_iterator_invalid_setstate) ... ok
test_iterator_pickling (test.test_range.RangeTest.test_iterator_pickling) ... ok
test_iterator_pickling_overflowing_index (test.test_range.RangeTest.test_iterator_pickling_overflowing_index) ... ok
test_iterator_setstate (test.test_range.RangeTest.test_iterator_setstate) ... ok
test_iterator_unpickle_compat (test.test_range.RangeTest.test_iterator_unpickle_compat) ... ok
test_large_exhausted_iterator_pickling (test.test_range.RangeTest.test_large_exhausted_iterator_pickling) ... ok
test_large_operands (test.test_range.RangeTest.test_large_operands) ... ok
test_large_range (test.test_range.RangeTest.test_large_range) ... ok
test_odd_bug (test.test_range.RangeTest.test_odd_bug) ... ok
test_pickling (test.test_range.RangeTest.test_pickling) ... ok
test_range (test.test_range.RangeTest.test_range) ... ok
test_range_constructor_error_messages (test.test_range.RangeTest.test_range_constructor_error_messages) ... ok
test_range_iterators (test.test_range.RangeTest.test_range_iterators) ... ok
test_range_iterators_invocation (test.test_range.RangeTest.test_range_iterators_invocation) ... ok
test_repr (test.test_range.RangeTest.test_repr) ... ok
test_reverse_iteration (test.test_range.RangeTest.test_reverse_iteration) ... ok
test_slice (test.test_range.RangeTest.test_slice) ... ok
test_strided_limits (test.test_range.RangeTest.test_strided_limits) ... ok
test_types (test.test_range.RangeTest.test_types) ... ok
test_user_index_method (test.test_range.RangeTest.test_user_index_method) ... ok
----------------------------------------------------------------------
Ran 29 tests in 1.076s
OK
Warning -- files was modified by test_range
Warning -- Before: ['.azure-pipelines/', '.coveragerc', '.devcontainer/', '.editorconfig', '.git/', '.gitattributes', '.github/', '.gitignore', '.mailmap', '.pre-commit-config.yaml', '.readthedocs.yml', '.ruff.toml', '.well-known/', 'Android/', 'Apple/', 'Doc/', 'Grammar/', 'Include/', 'InternalDocs/', 'LICENSE', 'Lib/', 'Mac/', 'Makefile.pre.in', 'Misc/', 'Modules/', 'Objects/', 'PC/', 'PCbuild/', 'Parser/', 'Platforms/', 'Programs/', 'Python/', 'README.rst', 'Tools/', 'aclocal.m4', 'config.guess', 'config.sub', 'configure', 'configure.ac', 'iOS/', 'install-sh', 'pyconfig.h.in', 'python.bat']
Warning -- After: ['.azure-pipelines/', '.coveragerc', '.devcontainer/', '.editorconfig', '.git/', '.gitattributes', '.github/', '.gitignore', '.mailmap', '.pre-commit-config.yaml', '.readthedocs.yml', '.ruff.toml', '.well-known/', 'Android/', 'Apple/', 'Doc/', 'Grammar/', 'Include/', 'InternalDocs/', 'LICENSE', 'Lib/', 'Mac/', 'Makefile.pre.in', 'Misc/', 'Modules/', 'Objects/', 'PC/', 'PCbuild/', 'Parser/', 'Platforms/', 'Programs/', 'Python/', 'README.rst', 'Tools/', 'aclocal.m4', 'config.guess', 'config.sub', 'configure', 'configure.ac', 'iOS/', 'install-sh', 'junk95142.zip', 'pyconfig.h.in', 'python.bat', 'ziptestmodule']
On Windows, sys.getfilesystemencoding() returns 'mbcs' rather than 'utf-8'.
That's wrong: sys.getfilesystemencoding() returns utf-8 on Windows. You can see FS=utf-8 in logs above (line == encodings: locale=cp1252 FS=utf-8).
You can also see sys.filesystem_encoding: utf-8/surrogatepass in the previous build step, in "Display build info".
Steps to Reproduce:
(...)
PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --tempdir="%TEMP%"
I built Python in debug mode and I ran:
PCbuild\rt.bat -d -q -uall -u-cpu -rwW --slowest --timeout=1200 -j1 test_range --tempdir=%TEMP%
I'm unable to reproduce the error.
I am sorry. The real error message is
tests may fail, unable to create temporary directory 'D:\\a\\1\\s\\build\\test_python_9140æ': [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_9140æ'
Traceback (most recent call last):
File "D:\a\1\s\Lib\test\support\os_helper.py", line 524, in temp_dir
os.mkdir(path)
~~~~~~~~^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_9140æ'
Stack (most recent call last):
File "<frozen runpy>", line 196, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 138, in <module>
main()
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 133, in main
with os_helper.temp_cwd(work_dir, quiet=True):
File "D:\a\1\s\Lib\contextlib.py", line 141, in __enter__
return next(self.gen)
File "D:\a\1\s\Lib\test\support\os_helper.py", line 597, in temp_cwd
with temp_dir(path=name, quiet=quiet) as temp_path:
tests may fail, unable to change the current working directory to 'D:\\a\\1\\s\\build\\test_python_9140æ': [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_9140æ'
Traceback (most recent call last):
File "D:\a\1\s\Lib\test\support\os_helper.py", line 563, in change_cwd
os.chdir(os.path.realpath(path))
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\a\\1\\s\\build\\test_python_9140æ'
Stack (most recent call last):
File "<frozen runpy>", line 196, in _run_module_as_main
File "<frozen runpy>", line 87, in _run_code
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 138, in <module>
main()
File "D:\a\1\s\Lib\test\libregrtest\worker.py", line 133, in main
with os_helper.temp_cwd(work_dir, quiet=True):
File "D:\a\1\s\Lib\contextlib.py", line 141, in __enter__
return next(self.gen)
File "D:\a\1\s\Lib\test\support\os_helper.py", line 598, in temp_cwd
with change_cwd(temp_path, quiet=quiet) as cwd_dir:
This is only a example.
It seems that some of functions still use non-Unicode Windows API.
We use non-ASCII temporary directory name specially to catch such bugs.
It seems that some of functions still use non-Unicode Windows API.
At least, os.chdir() is implemented with SetCurrentDirectoryW() which takes a wide string (LPCWSTR path).
This is only a example.
@Aasyaco: Can you reproduce the error outside the Azure Pipeline?
@vstinner Thank you for the patience and correction.
The traceback shows the corrupted path test_python_9140æ is
already invalid before reaching os_helper.temp_cwd() — the
corruption happens upstream in libregrtest/worker.py line 133,
where work_dir is constructed. The os_helper code is just the crash site, not the source.
I also want to correct my earlier analysis: the root cause is not
test_itertools or mbcs filesystem encoding. I apologise for the inaccurate attribution.
pythongh-146202: Create tmp_dir in regrtest worker
tests may fail, unable to create temporary directory 'D:\a\1\s\build\test_python_4940æ': [WinError 3] The system cannot find the path specified: 'D:\a\1\s\build\test_python_4940æ'
This error means that the D:\a\1\s\build\ directory (the build directory) doesn't exist. When the --tempdir option is used, the main process doesn't create the "build" directory. It seems like sometimes, the build directory is created. Sometimes not, causing tons errors related to temp_cwd() and change_cwd().
I wrote #146347 to fix regrtest.
See also this old issue about the same bug in 2023: #110644.
Note: This error is unrelated to the filesystem encoding.
Most Azure Pipeline jobs are green because tests are re-run, and they pass when they are re-run.
But many tests are re-run: https://dev.azure.com/Python/cpython/_build/results?buildId=168944&view=logs&j=c8a71634-e5ec-54a0-3958-760f4148b765&t=ddcdae4e-111a-5c2a-2289-6b784c553924
43 re-run tests:
test.test_asyncio.test_base_events test.test_asyncio.test_locks
test.test_asyncio.test_server test.test_asyncio.test_staggered
test.test_concurrent_futures.test_thread_pool
test.test_multiprocessing_spawn.test_processes
test.test_os.test_os test.test_pydoc.test_pydoc test___all__
test__interpreters test_argparse test_base64 test_binop
test_codeccallbacks test_compileall test_ctypes test_dbm_dumb
test_eof test_finalization test_graphlib test_imaplib
test_itertools test_keywordonlyarg test_lazy_import test_list
test_mmap test_module test_ntpath test_pathlib test_profiling
test_pyexpat test_regrtest test_runpy test_sched test_ssl test_sys
test_tabnanny test_traceback test_ucn test_venv test_wave
test_zipfile test_zipimport
455 tests OK.
pythongh-146202: Create tmp_dir in regrtest worker (pythonGH-146347)
pythongh-146202: Create tmp_dir in regrtest worker (pythonGH-146347)
The issue is fixed in the latest Azure Pipeline job: https://dev.azure.com/Python/cpython/_build/results?buildId=168959&view=results
455 tests OK.
There are no longer re-run tests.
Merge branch 'fix-pythongh-138577' of github.com:CuriousLearner/cpyth…
@vstinner thank you so much.
pythongh-146202: Create tmp_dir in regrtest worker (python#146347)
pythongh-146202: Create tmp_dir in regrtest worker (python#146347)