Skip to content

Use tmp_path pytest fixture over tmpdir #2364

@matthewfeickert

Description

@matthewfeickert

tmp_path is a modern replacement for tmpdir, by the way.

Thanks and noted.

From the pytest docs (https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html#the-tmpdir-and-tmpdir-factory-fixtures):

The tmpdir and tmpdir_factory fixtures are similar to tmp_path and tmp_path_factory, but use/return legacy py.path.local objects rather than standard pathlib.Path objects.

Note

These days, it is preferred to use tmp_path and tmp_path_factory.

In order to help modernize old code bases, one can run pytest with the legacypath plugin disabled:

pytest -p no:legacypath

This will trigger errors on tests using the legacy paths. It can also be permanently set as part of the addopts parameter in the config file.

We'll fix this up in another PR. 👍

Originally posted by @matthewfeickert in #2363 (comment) given feedback from @henryiii

Metadata

Metadata

Assignees

No one assigned

    Labels

    choreOther changes that don't modify src or test fileshelp wantedExtra attention is needed / contributions welcometestspytest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions