pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Fix: Skip system temp directories in rootdir detection (issue #13822)

Open AddyM opened this issue 1 month ago • 2 comments

Summary

Fixes #13822

When /tmp/setup.py exists on the system, pytest incorrectly identifies /tmp as the project root, causing test node IDs to include full paths under /tmp instead of relative paths.

Changes

  • Added _is_system_temp_or_parent() helper function to detect system temp directories
  • Modified determine_setup() to skip system temp directories when searching for setup.py
  • Uses tempfile.gettempdir() for cross-platform compatibility

Testing

  • Verified helper function correctly identifies system temp directory
  • Tested that regular directories are not flagged as temp
  • Manual testing confirms /tmp/setup.py no longer affects rootdir detection

Backward Compatibility

  • No breaking changes
  • Users can still use --rootdir to override if needed
  • Only affects systems with setup.py in system temp directories

AddyM avatar Oct 18 '25 21:10 AddyM