Skip to content

Make test_compileall's path-like output checks effective - #161775

Open
andresdelfino wants to merge 1 commit into
python:mainfrom
andresdelfino:test-compileall-pathlike-output
Open

andresdelfino wants to merge 1 commit into
python:mainfrom
andresdelfino:test-compileall-pathlike-output

Conversation

@andresdelfino

Copy link
Copy Markdown
Contributor

test_compile_file_pathlike and test_compile_dir_pathlike check the output with:

self.assertRegex(stdout.getvalue(), r'Compiling ([^WindowsPath|PosixPath].*)')
self.assertRegex(line, r'Listing ([^WindowsPath|PosixPath].*)')

[^WindowsPath|PosixPath] is a negated character class, not "anything but WindowsPath or PosixPath": it only checks that the first character after Compiling / Listing isn't one of W i n d o w s P a t h | x. That worked when the tests used pathlib.Path, but since gh-119064 switched them to FakePath, whose repr is <FakePath '...'>, the regex matches no matter what is printed.

With a modified compileall that prints the path-like object's repr, both tests still pass:

Compiling <FakePath '/tmp/tmp04a_tttu/_test.py'>...
Listing <FakePath '/tmp/tmp04a_tttu'>...

This PR compares against the exact expected line instead, which is what the tests did before d8e9713. Using !r matches the quoting and Windows backslash escaping compileall prints, which is why the regex was introduced. With this change, the modified compileall makes both tests fail, and the unmodified one passes.

🤖 Generated with Claude Code

The regex `[^WindowsPath|PosixPath]` is a negated character class: it only
checks that the first character after "Compiling " / "Listing " is not one
of those letters.  Since the tests switched from pathlib.Path to FakePath
(pythongh-119064), whose repr starts with "<", the regex matches even if
compileall prints the repr of the path-like object instead of the path.

Compare against the exact expected line instead, using !r so the quoting
and Windows backslash escaping match what compileall prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bedevere-app bedevere-app Bot added tests Tests in the Lib/test dir awaiting review labels Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant