Skip to content

Conversation

@Shrikantgiri25
Copy link

@Shrikantgiri25 Shrikantgiri25 commented Oct 24, 2025

What this PR does

  • Fixes TestRegularFieldMappings.test_regular_fields failure on Windows + Python 3.13
  • Removes leftover print() statements in tests/schemas/test_openapi.py

Background / Why

While setting up DRF on Windows 11 with Python 3.13,
I noticed:
Some serializer tests failed due to unescaped backslashes in Windows paths
Regex matching in TestRegularFieldMappings was too strict for platform-specific variations
Debug print() statements cluttered test output and were unnecessary
These issues prevent Windows developers from running the full test suite successfully and affect cross-platform reliability.

How I fixed it

  • Escaped backslashes in Windows paths using re.escape()
  • Relaxed regex patterns for dynamic fields (e.g., IntegerField and CustomField) using .* and re.DOTALL to allow cross-platform compatibility
  • Removed all redundant print() statements in test_openapi.py
  • Tested the full test suite locally on both Windows 11 + Python 3.13 and Linux (via WSL), and all tests ran successfully

Impact

  • Windows developers can run DRF tests locally without failures
  • Test suite is cleaner, more maintainable, and platform-independent
  • Validation logic for core fields remains intact

Discussion / Reference

Original discussion: DRF Discussion #9807

Notes

  • Ready for review and feedback from maintainers
  • Can be split into separate PRs if preferred (one for test fix, one for cleanup)

Verified screenshots

window:

image

wsl:

image

@auvipy auvipy requested review from auvipy and Copilot October 25, 2025 07:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

auvipy
auvipy previously approved these changes Oct 25, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Shrikant Giri added 2 commits October 25, 2025 14:43
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.
@p-r-a-v-i-n
Copy link
Contributor

I just wanted to share my perspective here:

  1. This change only affects a test and doesn’t impact any runtime behavior , so it adds more complexity compare to benefits.
  2. It might increases the chance of breaking the test if the serializer fields or repr() format change in future
  3. DRF generally aims to keep its tests simple and platform-agnostic. In practice, the test suite is not officially guaranteed to pass on native Windows.
  4. maintenance burden for non-production code.

windows user can use wsl

@Shrikantgiri25
Copy link
Author

Shrikantgiri25 commented Oct 25, 2025

I just wanted to share my perspective here:

  1. This change only affects a test and doesn’t impact any runtime behavior , so it adds more complexity compare to benefits.
  2. It might increases the chance of breaking the test if the serializer fields or repr() format change in future
  3. DRF generally aims to keep its tests simple and platform-agnostic. In practice, the test suite is not officially guaranteed to pass on native Windows.
  4. maintenance burden for non-production code.

windows user can use wsl

Thanks @p-r-a-v-i-n for the feedback! I completely understand your perspective — I just wanted to share a bit more context on why I approached it this way:

On complexity:
This is only 4-7 lines of actual code. The added comments simply document platform differences for future maintainers — they don’t add complexity; they improve clarity.

On Windows support:
While WSL exists, not every developer can use it:

  • Corporate environments with IT restrictions

  • Educational institutions with locked-down systems

  • Beginners learning Python who aren’t ready to set up Linux

  • Developers using hardware with limited virtualization support

Ensuring tests run natively on Windows helps all of these contributors.

On maintenance:
This test already needs updating if the repr() output format changes.
The modification doesn’t increase that risk — it simply ensures the test works consistently across platforms.

On philosophy:
Django itself handles cross-platform differences in its own test suite.
Making DRF’s tests run cross-platform aligns with Python’s “batteries included” philosophy and lowers barriers for contributors.

That said, if the maintainers prefer to keep DRF tests Linux-only, I completely understand and can withdraw the PR — no hard feelings.

Just wanted to help make contributing easier for Windows developers!

Background: I also want to share that I primarily work on Windows for personal/work reasons. While WSL is available, my current setup is Windows-native. When I tried to set up the DRF repo and run the test suite to verify my local environment, I encountered these platform-specific failures.
If this test fails on Windows(Failing Screenshots here in discussion), new developers might assume their setup is broken(I felt this when I tried to set up the project) or misconfigured, potentially causing confusion, extra support queries, or wasted time.
The test already existed; my changes simply make it multi-platform compatible, so Windows developers can run the suite successfully and verify their environment.

Note: This test was already present in the codebase — I’ve only modified it slightly to make it multi-platform compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants