Fix Windows test failures and remove debug prints for DRF#9808
Fix Windows test failures and remove debug prints for DRF#9808browniebroke merged 5 commits intoencode:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes cross-platform test failures on Windows with Python 3.13 and removes debug print statements from the test suite. The main changes ensure that path-based tests handle Windows backslashes correctly and that regex patterns are flexible enough to accommodate platform-specific variations in object representations.
- Fixed Windows path escaping issues in
TestRegularFieldMappings.test_regular_fields - Relaxed regex patterns to handle cross-platform differences in object string representations
- Removed 7 debug print() statements from OpenAPI schema tests
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_model_serializer.py | Updated regex patterns to handle Windows paths and cross-platform object representations; added re.DOTALL flag for multi-line matching |
| tests/schemas/test_openapi.py | Removed debug print() statements that were cluttering test output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I just wanted to share my perspective here:
windows user can use wsl |
|
Hi 👋 just following up on this PR. |
|
The removal of the print statements make complete sense to me, but I'm a bit more on the fence on the rest of the PR. To Pravin's point, it does introduce some complexity which I'm not sure is worth it. It seems to also change some lines which are unrelated at first glance... I might be missing something here. It's better to keep changes minimal and separated, if you send a PR for removing the print statement, I'm happy to accept it. |
Hi @browniebroke ,
This would avoid introducing additional complexity. Thanks for your guidance! |
|
Yes that seems |
Windows requires manual backslash replacement for repr() matching:
- repr() displays C:\Users as 'C:\Users' (double backslashes)
- Regex needs \\ to match \ (four backslashes in pattern)
- re.escape() only produces \ (matches single backslash)
Test evidence on Windows:
re.escape(path) in repr(path): None (fails)
path.replace('\', r'\\') in repr(path): Match (works)
Solution:
- Windows: Manual replacement for repr() double-escaping
- Unix: re.escape() for special character handling
Addresses @auvipy's review with detailed testing and explanation.
Great, thanks! I'll update the PR to use the skip approach + print removals. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
43da74e to
c601602
Compare
|
Hi all, updated the PR to use @pytest.mark.skipif for the test. |
|
Hi @auvipy I hope you’re doing well. I wanted to kindly follow up on this PR. I’ve updated it based on the initial feedback and would be happy to make any further adjustments if needed. Thank you! |
What this PR does
TestRegularFieldMappings.test_regular_fieldsprint()statements intests/schemas/test_openapi.pyBackground / Why
While setting up DRF on Windows 11 with Python 3.13, I noticed:
TestRegularFieldMappings.test_regular_fieldsfails on Windows due to backslash escaping differences in path representations (repr(path)shows'C:\\Users'on Windows)print()statements cluttered test outputHow I fixed it
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Test not supported on Windows")to skip the Windows-incompatible test (follows existing pattern used intest_decorators.py)print()statements intest_openapi.pyImpact
Discussion / Reference
Original discussion: DRF Discussion #9807