From 4736b2bdfb99f66f998cdc387627d64fd38447d1 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 11 Oct 2018 15:33:19 +0200 Subject: [PATCH] address review comments --- .pre-commit-config.yaml | 2 +- changelog/3988.deprecation.rst | 1 + doc/en/tmpdir.rst | 14 +++++++++----- src/_pytest/tmpdir.py | 12 ++++++------ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 changelog/3988.deprecation.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc6d9e10c57..e5cc5623020 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,6 @@ repos: - id: changelogs-rst name: changelog filenames language: fail - entry: 'changelog files must be named ####.(feature|bugfix|doc|removal|vendor|trivial).rst' + entry: 'changelog files must be named ####.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst' exclude: changelog/(\d+\.(feature|bugfix|doc|deprecation|removal|vendor|trivial).rst|README.rst|_template.rst) files: ^changelog/ diff --git a/changelog/3988.deprecation.rst b/changelog/3988.deprecation.rst new file mode 100644 index 00000000000..b731112e47e --- /dev/null +++ b/changelog/3988.deprecation.rst @@ -0,0 +1 @@ +Add a Deprecation warning for pytest.ensuretemp as it was deprecated since a while. diff --git a/doc/en/tmpdir.rst b/doc/en/tmpdir.rst index 1c815c8d1b2..7286211525f 100644 --- a/doc/en/tmpdir.rst +++ b/doc/en/tmpdir.rst @@ -6,7 +6,7 @@ Temporary directories and files ================================================ The ``tmp_path`` fixture ----------------------- +------------------------ .. versionadded:: 3.9 @@ -15,12 +15,16 @@ You can use the ``tmpdir`` fixture which will provide a temporary directory unique to the test invocation, created in the `base temporary directory`_. -``tmpdir`` is a `pathlib/pathlib2.Path`_ object. Here is an example test usage:: +``tmpdir`` is a ``pathlib/pathlib2.Path`` object. Here is an example test usage: + +.. code-block:: python # content of test_tmp_path.py import os + CONTENT = u"content" + def test_create_file(tmp_path): d = tmp_path / "sub" d.mkdir() @@ -38,8 +42,8 @@ Running this would result in a passed test except for the last -The ``tmp_path_facotry`` fixture ------------------------------- +The ``tmp_path_factory`` fixture +-------------------------------- .. versionadded:: 3.9 @@ -47,7 +51,7 @@ The ``tmp_path_facotry`` fixture The ``tmp_path_facotry`` is a session-scoped fixture which can be used to create arbitrary temporary directories from any other fixture or test. -its intended to replace ``tmpdir_factory`` +its intended to replace ``tmpdir_factory`` and returns :class:`pathlib.Path` instances. The 'tmpdir' fixture diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index e86994b8e88..1963f14c00b 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -25,8 +25,8 @@ class TempPathFactory(object): The base directory can be configured using the ``--basetemp`` option.""" - given_basetemp = attr.ib() - trace = attr.ib() + _given_basetemp = attr.ib() + _trace = attr.ib() _basetemp = attr.ib(default=None) @classmethod @@ -45,14 +45,14 @@ def mktemp(self, basename, numbered=True): p.mkdir() else: p = make_numbered_dir(root=self.getbasetemp(), prefix=basename) - self.trace("mktemp", p) + self._trace("mktemp", p) return p def getbasetemp(self): """ return base temporary directory. """ if self._basetemp is None: - if self.given_basetemp is not None: - basetemp = Path(self.given_basetemp) + if self._given_basetemp is not None: + basetemp = Path(self._given_basetemp) ensure_reset_dir(basetemp) else: from_env = os.environ.get("PYTEST_DEBUG_TEMPROOT") @@ -67,7 +67,7 @@ def getbasetemp(self): ) assert basetemp is not None self._basetemp = t = basetemp - self.trace("new basetemp", t) + self._trace("new basetemp", t) return t else: return self._basetemp