From 70cac3d464905cb3f7cedba9ea4f61dc56613f55 Mon Sep 17 00:00:00 2001 From: Wolfremium <64548160+Wolfremium13@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:40:18 +0100 Subject: [PATCH] Explicit note that tmpdir fixture is discouraged in favour of tmp_path #9937 (#10138) Co-authored-by: Bruno Oliveira Co-authored-by: kevin.hierro-ext Co-authored-by: Dani Sancas --- AUTHORS | 4 ++++ changelog/9937.doc.rst | 1 + doc/en/how-to/tmp_path.rst | 6 ++++-- src/_pytest/legacypath.py | 14 +++++++++++++- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 changelog/9937.doc.rst diff --git a/AUTHORS b/AUTHORS index b0669ba29..b8e6377fb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -87,6 +87,7 @@ Damian Skrzypczak Daniel Grana Daniel Hahler Daniel Nuri +Daniel Sánchez Castelló Daniel Wandschneider Daniele Procida Danielle Jenkins @@ -190,6 +191,7 @@ Katerina Koukiou Keri Volans Kevin C Kevin Cox +Kevin Hierro Carrasco Kevin J. Foley Kian Eliasi Kian-Meng Ang @@ -328,6 +330,7 @@ Taneli Hukkinen Tanvi Mehta Tarcisio Fischer Tareq Alayan +Tatiana Ovary Ted Xiao Terje Runde Thomas Grainger @@ -346,6 +349,7 @@ Tyler Goodlet Tzu-ping Chung Vasily Kuznetsov Victor Maryama +Victor Rodriguez Victor Uriarte Vidar T. Fauske Virgil Dupras diff --git a/changelog/9937.doc.rst b/changelog/9937.doc.rst new file mode 100644 index 000000000..326d20ec8 --- /dev/null +++ b/changelog/9937.doc.rst @@ -0,0 +1 @@ +Explicit note that :fixture:`tmpdir` fixture is discouraged in favour of :fixture:`tmp_path`. diff --git a/doc/en/how-to/tmp_path.rst b/doc/en/how-to/tmp_path.rst index b261a5563..99e9e5536 100644 --- a/doc/en/how-to/tmp_path.rst +++ b/doc/en/how-to/tmp_path.rst @@ -104,8 +104,10 @@ 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 :class:`pathlib.Path` objects. These days, prefer to -use ``tmp_path`` and ``tmp_path_factory``. +rather than standard :class:`pathlib.Path` objects. + +.. note:: + These days, it is preferred to use ``tmp_path`` and ``tmp_path_factory``. See :fixture:`tmpdir ` :fixture:`tmpdir_factory ` API for details. diff --git a/src/_pytest/legacypath.py b/src/_pytest/legacypath.py index 49149311a..f71e7e96e 100644 --- a/src/_pytest/legacypath.py +++ b/src/_pytest/legacypath.py @@ -271,7 +271,14 @@ class LegacyTestdirPlugin: @attr.s(init=False, auto_attribs=True) class TempdirFactory: """Backward compatibility wrapper that implements :class:`py.path.local` - for :class:`TempPathFactory`.""" + for :class:`TempPathFactory`. + + .. note:: + These days, it is preferred to use ``tmp_path_factory``. + + :ref:`About the tmpdir and tmpdir_factory fixtures`. + + """ _tmppath_factory: TempPathFactory @@ -312,6 +319,11 @@ class LegacyTmpdirPlugin: The returned object is a `legacy_path`_ object. + .. note:: + These days, it is preferred to use ``tmp_path``. + + :ref:`About the tmpdir and tmpdir_factory fixtures`. + .. _legacy_path: https://py.readthedocs.io/en/latest/path.html """ return legacy_path(tmp_path)