Skip to content

data loss with mistyped --basetemp #7119

@ndevenish

Description

@ndevenish

This 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

converter=attr.converters.optional(
lambda p: Path(os.path.abspath(str(p))) # type: ignore
),
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributorplugin: tmpdirrelated to the tmpdir builtin plugintype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions