Skip to content

Conversation

@AddyM
Copy link

@AddyM AddyM commented Oct 18, 2025

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

Aditya Mehra and others added 2 commits October 18, 2025 17:43
…dev#13822)

- Add helper function _is_system_temp_or_parent() to detect system temp dir
- Modify determine_setup() to skip /tmp when searching for setup.py
- Prevents pytest from incorrectly using /tmp as rootdir when /tmp/setup.py exists

Fixes pytest-dev#13822
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Thanks @AddyM,

Could you please add a test to ensure this does not regress? You can monkeypatch tempfile.gettempdir() to avoid adding files to the system's temporary directory.

Aditya Mehra and others added 3 commits October 20, 2025 12:04
- Test verifies that setup.py in system temp dir is ignored
- Uses monkeypatch to simulate /tmp/setup.py without touching system
- Ensures rootdir detection works correctly
@AddyM
Copy link
Author

AddyM commented Oct 20, 2025

Thanks @AddyM,

Could you please add a test to ensure this does not regress? You can monkeypatch tempfile.gettempdir() to avoid adding files to the system's temporary directory.

Hello @nicoddemus , thanks a lot for the input , added a regression test .Please help in reviewing . Thanks

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.

Test failure when /tmp/setup.py exists

2 participants