Repository navigation
Tests: error "tests may fail, unable to create temporary directory (...): [WinError 3] The system cannot find the path specified" on Windows #146202
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortestsTests in the Lib/test dirTests in the Lib/test dir
on Mar 20, 2026 Azure 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-6b784c553924Extract 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-8on Windows. You can seeFS=utf-8in logs above (line== encodings: locale=cp1252 FS=utf-8).You can also see
sys.filesystem_encoding: utf-8/surrogatepassin 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 withSetCurrentDirectoryW()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 reachingos_helper.temp_cwd()— the
corruption happens upstream inlibregrtest/worker.pyline 133,
wherework_diris constructed. Theos_helpercode is just the crash site, not the source.I also want to correct my earlier analysis: the root cause is not
test_itertoolsormbcsfilesystem encoding. I apologise for the inaccurate attribution.- added a commit that references this issue
on Mar 23, 2026 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 (thebuilddirectory) doesn't exist. When the--tempdiroption is used, the main process doesn't create the "build" directory. It seems like sometimes, thebuilddirectory is created. Sometimes not, causing tons errors related totemp_cwd()andchange_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.
- changed the title
[-]test_itertools: non-ASCII temp dir name corrupted under Windows mbcs codepage and not removed, causing FileNotFoundError in subsequent tests[/-][+]Tests: error "tests may fail, unable to create temporary directory (...): [WinError 3] The system cannot find the path specified" on Windows[/+]on Mar 23, 2026 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.- added a commit that references this issue
on Mar 23, 2026 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.
@vstinner thank you so much.
Reacted by Victor Stinner
Windows CI failure:
test_itertoolscorrupts Unicode temp directory name undermbcsencoding, breaks subsequent testsSummary
On Windows (official Azure CI), the CPython 3.15 test suite produces cascading failures originating from
test_itertools. The test creates a temporary directory whose name contains a non-ASCII character. Because the Windows default filesystem encoding ismbcs, the Unicode byte sequence is misinterpreted and the directory name becomes corrupted on disk. The directory is never cleaned up, which causes all subsequent tests that create temporary directories to fail withFileNotFoundError.CPython Version
Operating System / Platform
Filesystem Encoding
CI Pipeline Context
Build step:
Test step:
Azure 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
Steps to Reproduce
mainbranch.packageæ/) left behind in the temp directory.FileNotFoundError.Expected Behavior
Actual Behavior
test_itertoolscreates a directory whose name contains a non-ASCII character (e.g.æ).mbcs), the Unicode name is misinterpreted:æ(U+00E6) is stored asæ.test_itertoolscompletes.test_class,test_pdb) fail when attempting to create temporary directories because the corrupted entry causesos_helper.temp_dirto raiseFileNotFoundError.test_itertoolsand marks unrelated tests as failed, significantly increasing triage cost.Relevant Log Excerpt
From Azure build 168864:
Root Cause (Analysis)
Two independent problems combine to produce this failure:
1. Encoding mismatch in
test_itertoolsThe test constructs or receives a directory name containing a non-ASCII character. On Windows,
sys.getfilesystemencoding()returns'mbcs'rather than'utf-8'. The UTF-8 byte sequence foræ(0xC3 0xA6) is reinterpreted under the ANSI code page as two separate characters, producing the visible corruptionæ. This is a violation of cross-platform Unicode path handling requirements.2. Missing cleanup in
test_itertoolsThe test creates the directory but does not register it for cleanup (e.g. via
addCleanup,self.addCleanup, or a context manager such astempfile.TemporaryDirectory). The corrupted directory persists in the shared--tempdirlocation for the duration of the entire test run, causing every subsequent call toos_helper.temp_dirto fail withWinError 3.Impact
test_itertoolsrunsFiles Involved
Lib/test/test_itertools.py— primary location of the encoding issue and missing cleanupLib/test/support/os_helper.py— secondary impact point (temp_dircontext manager)Linked Resources
sys.getfilesystemencoding()docs: https://docs.python.org/3/library/sys.html#sys.getfilesystemencodingos.fsencode()docs: https://docs.python.org/3/library/os.html#os.fsencodeLinked PRs