pytest
pytest copied to clipboard
Fix: Skip system temp directories in rootdir detection (issue #13822)
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 forsetup.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
--rootdirto override if needed - Only affects systems with setup.py in system temp directories