pytest-dev / pytest-dev/pytest

Allow to change permissions of temp directories created with tmp_path

Open
#10,679 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: tmpdir
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

What's the problem this feature will solve?

Any temp directory created with the fixture tmp_path has read/write permissions only for the specific user running the tests because mode is set to 0o700.
Although this is probably motivated by security concerns, there are scenarios where more relaxed permissions can be useful.

Describe the solution you'd like

I'd like to be able to override the 0o700 mode that is currently hardcoded in pytest.

For example, the tests may be run in a CI pipeline by a special service user, that's different from the user that should investigate any possible error.
If the mode is set 0o750 and the users belong to the same group, the second user would be able to read the temp files.

Alternative Solutions

I tried to enforce chmod on the temp directory after the tests are executed, but this adds complexity and it's not enough if the pipeline is killed due to a timeout.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the tmp_path fixture and the hardcoded 0o700 assignment. Check how fixture options are configured elsewhere in pytest before deciding where an override belongs. Done means the secure default remains unchanged and callers can verify a requested mode such as 0o750 on created temporary directories.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.