-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue with slashes being turned into backslashes on Windows #12760
Fix issue with slashes being turned into backslashes on Windows #12760
Conversation
I’ve tackled the issue with backslashes getting messed up in I haven’t added unit tests yet—figured I’d wait to see if the approach looks good to you all. If it does, I’ll go ahead and write the tests to make sure everything’s covered. |
for more information, see https://pre-commit.ci
Co-authored-by: dongfangtianyu <7629022+dongfangtianyu@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @nauman897 for this PR.
I have debugged and verified it locally, and everything is fine.
testing/test_terminal.py
Outdated
|
||
|
||
class TestNodeIDHandling: | ||
def test_nodeid_handling_windows_paths(self, pytester: Pytester) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested this on Windows, on the main
branch, and it passes... does this fail only on Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nicoddemus ,
The problem specifically occurs under these circumstances as mentioned in the issue:
The IDs show up correctly in --collect-only, and they show correctly when test_x.py is not in a subfolder, or when pytest is not invoked in the subfolder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then the test case should make sure to replicate that scenario, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I'll fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe @dongfangtianyu has already taken care of it: nauman897#1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nauman897 ,I have submitted a PR to your repository, hoping that you can review, verify, and merge this modification. It’s not difficult, you can give it a try.
Ideally:
- The test case will fail when pytest runs without your patch being merged.
- The test case will pass after merging your patch into pytest.
If the actual result is different, it indicates there are still issues with our code, and it should not be merged into pytest’s main
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dongfangtianyu for the help with these tests.
I can confirm that:
- The tests fail with the previous logic in
cwd_relative_nodeid
:
FAILED test_foo.py::test_x[x\y] - assert False
FAILED test_foo.py::test_x[C:\path] - assert False
FAILED test_foo.py::test_x[\] - assert False
FAILED test_foo.py::test_x[C:\path] - assert False
FAILED test_foo.py::test_x[a::b\] - assert False
- The tests pass after the patch is applied.
test_foo.py::test_x[x/y] FAILED [ 20%]
test_foo.py::test_x[C:/path] FAILED [ 40%]
test_foo.py::test_x[\\] FAILED [ 60%]
test_foo.py::test_x[C:\\path] FAILED [ 80%]
test_foo.py::test_x[a::b/] FAILED [100%]
I had to make a minor adjustment to the new tests, as Python 3.11 and later requires passing the encoding_type
param while calling the write_text
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cool @nauman897 !
- The tests pass after the patch is applied.
test_terminal.py::TestNodeIDHandling::test_nodeid_handling_windows_paths PASSED [100%]
This is a more intuitive output:
test_foo.py::test_x[x/y] FAILED [ 20%]
test_foo.py::test_x[C:/path] FAILED [ 40%]
test_foo.py::test_x[\\] FAILED [ 60%]
test_foo.py::test_x[C:\\path] FAILED [ 80%]
test_foo.py::test_x[a::b/] FAILED [100%]
updated the tests
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks folks, we greatly appreciate it!
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #12787 🤖 @patchback |
Fix slash handling in nodeid paths for Windows environments.
nodeid
paths on Windows.