Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Oct 11, 2018
1 parent 584051a commit 4736b2b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions changelog/3988.deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a Deprecation warning for pytest.ensuretemp as it was deprecated since a while.
14 changes: 9 additions & 5 deletions doc/en/tmpdir.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Temporary directories and files
================================================

The ``tmp_path`` fixture
----------------------
------------------------

.. versionadded:: 3.9

Expand All @@ -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()
Expand All @@ -38,16 +42,16 @@ 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


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
Expand Down
12 changes: 6 additions & 6 deletions src/_pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit 4736b2b

Please sign in to comment.