data loss with mistyped --basetemp
See original GitHub issueThis might entirely class “user error”, but I mistyped the pytest launch command and lost my entire source repository, e.g. commits, stashes and WIP branches (most backed up, luckily). The system I was running on only had a small /tmp
available so I wanted to change the path. Unfortunately I left a space in pytest --basetmp= /scratch/tmp .
- this wiped out the entire working directory. It has the same behaviour if you don’t provide a path:
mkdir test_folder
cd test_folder
echo -e "def test_a(tmpdir):\n pass" >> test_a.py
pytest --basetmp= .
I note that the argument help says “(warning: this directory is removed if it exists)” but isn’t mentioned on https://docs.pytest.org/en/latest/tmpdir.html#the-default-base-temporary-directory - and wouldn’t protect against a typo anyway.
Only accepting folders that don’t exist or that it’s used before (with a breadcrumb file?) seem like A Fix, but changes the way it works and is more complicated. It might be simpler to be slightly safer? Is there any scenario in which allowing this option to be empty for the current working directory makes sense?
Cause looks to be https://github.com/pytest-dev/pytest/blob/3d0f3baa2bb89257dfff25ae6ebabd565287240e/src/_pytest/tmpdir.py#L31-L33 where attr.converters.optional
treats an empty string as “Not None” and os.path.abspath
interprets an empty string as cwd.
Pytest 5.4.1.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Actually it should error
Indeed @pangloss, thanks for the ping! We are still in the process of reviewing everything for 6.0, and indeed this is a serious issue.
The PR has now been merged. 👍