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
Windows CI failure: test_itertools corrupts Unicode temp directory name under mbcs encoding, breaks subsequent tests
Summary
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 is mbcs, 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 with FileNotFoundError.
CPython Version
Python 3.15.0a7 (main branch)
Operating System / Platform
Windows (Azure Pipelines Microsoft-hosted runner)
Filesystem Encoding
>>> import sys
>>> sys.getfilesystemencoding()
'mbcs'CI Pipeline Context
Build step:
PCbuild\build.bat -e $(buildOpt)
Test step:
PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 \
--junit-xml="$(Build.BinariesDirectory)\test-results.xml" \
--tempdir="$(Build.BinariesDirectory)\test"
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
- Check out the CPython
mainbranch. - Build on Windows:
PCbuild\build.bat -e <buildOpt> - Run the test suite:
PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 ^ -j0 --tempdir="%TEMP%" - Observe a directory with a corrupted name (e.g.
packageæ/) left behind in the temp directory. - Observe that subsequent tests fail with
FileNotFoundError.
Expected Behavior
- All tests pass cleanly on Windows during CI builds.
- No test leaves behind artifacts that interfere with other tests.
- Test isolation is preserved — temporary directories are created and removed correctly.
- Unicode filenames are handled consistently regardless of platform filesystem encoding.
Actual Behavior
test_itertoolscreates a directory whose name contains a non-ASCII character (e.g.æ).- Under the Windows default codepage (
mbcs), the Unicode name is misinterpreted:æ(U+00E6) is stored asæ. - The corrupted directory is not removed after
test_itertoolscompletes. - Subsequent tests (e.g.
test_class,test_pdb) fail when attempting to create temporary directories because the corrupted entry causesos_helper.temp_dirto raiseFileNotFoundError. - The runner reports a warning for
test_itertoolsand marks unrelated tests as failed, significantly increasing triage cost.
Relevant Log Excerpt
From Azure build 168864:
Warning -- files was modified by test_itertools
After: ... 'packageæ/'
test_class failed (env changed)
FileNotFoundError: [WinError 3] unable to create temporary directory:
'D:\a\1\s\build\test_python_9140æ'
Root Cause (Analysis)
Two independent problems combine to produce this failure:
1. Encoding mismatch in test_itertools
The 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_itertools
The test creates the directory but does not register it for cleanup (e.g. via addCleanup, self.addCleanup, or a context manager such as tempfile.TemporaryDirectory). The corrupted directory persists in the shared --tempdir location for the duration of the entire test run, causing every subsequent call to os_helper.temp_dir to fail with WinError 3.
Impact
| 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 |
Files 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
- Azure DevOps build 168864: https://dev.azure.com/Python/cpython/_build/results?buildId=168864
- PEP 529 — Change Windows filesystem encoding to UTF-8: https://peps.python.org/pep-0529/
sys.getfilesystemencoding()docs: https://docs.python.org/3/library/sys.html#sys.getfilesystemencodingos.fsencode()docs: https://docs.python.org/3/library/os.html#os.fsencode
Activity
vstinner commentedon Mar 20, 2026
Extract of logs:
vstinner commentedon Mar 20, 2026
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".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.
Aasyaco commentedon Mar 20, 2026
I am sorry. The real error message is
This is only a example.
serhiy-storchaka commentedon Mar 20, 2026
It seems that some of functions still use non-Unicode Windows API.
We use non-ASCII temporary directory name specially to catch such bugs.
vstinner commentedon Mar 20, 2026
At least,
os.chdir()is implemented withSetCurrentDirectoryW()which takes a wide string (LPCWSTR path).@Aasyaco: Can you reproduce the error outside the Azure Pipeline?
Aasyaco commentedon Mar 21, 2026
@vstinner Thank you for the patience and correction.
The traceback shows the corrupted path
test_python_9140æisalready invalid before reaching
os_helper.temp_cwd()— thecorruption happens upstream in
libregrtest/worker.pyline 133,where
work_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.pythongh-146202: Create tmp_dir in regrtest worker
vstinner commentedon Mar 23, 2026
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.
[-]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[/+]vstinner commentedon 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
gh-146202: Create tmp_dir in regrtest worker (#146347)
pythongh-146202: Create tmp_dir in regrtest worker (pythonGH-146347)
pythongh-146202: Create tmp_dir in regrtest worker (pythonGH-146347)
[3.13] gh-146202: Create tmp_dir in regrtest worker (GH-146347) (#146350
[3.14] gh-146202: Create tmp_dir in regrtest worker (GH-146347) (#146349
vstinner commentedon Mar 24, 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.
Merge branch 'fix-pythongh-138577' of github.com:CuriousLearner/cpyth…
Aasyaco commentedon Mar 24, 2026
@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)