diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc6d9e10c..e5cc56230 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 000000000..b731112e4 --- /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 1c815c8d1..728621152 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 e86994b8e..1963f14c0 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 @@ class TempPathFactory(object): 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 @@ class TempPathFactory(object): ) 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