summaryrefslogtreecommitdiff
path: root/src/_pytest/tmpdir.py
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-07-14 10:55:17 +0300
committerRan Benita <ran@unusedvar.com>2020-08-01 17:14:37 +0300
commit0242de4f5651818379bc0ff6326c97565a20a0f1 (patch)
treecbfc4c8dea3cb5b6ea3f355e4681927c2ea64e81 /src/_pytest/tmpdir.py
parent6882c0368b14e979642fdec0721a9922ba568074 (diff)
downloadpytest-0242de4f5651818379bc0ff6326c97565a20a0f1.tar.gz
Format docstrings in a consistent style
Diffstat (limited to 'src/_pytest/tmpdir.py')
-rw-r--r--src/_pytest/tmpdir.py66
1 files changed, 29 insertions, 37 deletions
diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py
index 58dd65908..017577a7a 100644
--- a/src/_pytest/tmpdir.py
+++ b/src/_pytest/tmpdir.py
@@ -1,4 +1,4 @@
-""" support for providing temporary directories to test functions. """
+"""Support for providing temporary directories to test functions."""
import os
import re
import tempfile
@@ -22,13 +22,14 @@ from _pytest.monkeypatch import MonkeyPatch
class TempPathFactory:
"""Factory for temporary directories under the common base temp directory.
- The base directory can be configured using the ``--basetemp`` option."""
+ The base directory can be configured using the ``--basetemp`` option.
+ """
_given_basetemp = attr.ib(
type=Path,
- # using os.path.abspath() to get absolute path instead of resolve() as it
- # does not work the same in all platforms (see #4427)
- # Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012)
+ # Use os.path.abspath() to get absolute path instead of resolve() as it
+ # does not work the same in all platforms (see #4427).
+ # Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012).
# Ignore type because of https://github.com/python/mypy/issues/6172.
converter=attr.converters.optional(
lambda p: Path(os.path.abspath(str(p))) # type: ignore
@@ -38,10 +39,8 @@ class TempPathFactory:
_basetemp = attr.ib(type=Optional[Path], default=None)
@classmethod
- def from_config(cls, config) -> "TempPathFactory":
- """
- :param config: a pytest configuration
- """
+ def from_config(cls, config: Config) -> "TempPathFactory":
+ """Create a factory according to pytest configuration."""
return cls(
given_basetemp=config.option.basetemp, trace=config.trace.get("tmpdir")
)
@@ -55,7 +54,7 @@ class TempPathFactory:
return basename
def mktemp(self, basename: str, numbered: bool = True) -> Path:
- """Creates a new temporary directory managed by the factory.
+ """Create a new temporary directory managed by the factory.
:param basename:
Directory base name, must be a relative path.
@@ -66,7 +65,7 @@ class TempPathFactory:
means that this function will create directories named ``"foo-0"``,
``"foo-1"``, ``"foo-2"`` and so on.
- :return:
+ :returns:
The path to the new directory.
"""
basename = self._ensure_relative_to_basetemp(basename)
@@ -79,7 +78,7 @@ class TempPathFactory:
return p
def getbasetemp(self) -> Path:
- """ return base temporary directory. """
+ """Return base temporary directory."""
if self._basetemp is not None:
return self._basetemp
@@ -106,28 +105,23 @@ class TempPathFactory:
@attr.s
class TempdirFactory:
- """
- backward comptibility wrapper that implements
- :class:``py.path.local`` for :class:``TempPathFactory``
- """
+ """Backward comptibility wrapper that implements :class:``py.path.local``
+ for :class:``TempPathFactory``."""
_tmppath_factory = attr.ib(type=TempPathFactory)
def mktemp(self, basename: str, numbered: bool = True) -> py.path.local:
- """
- Same as :meth:`TempPathFactory.mkdir`, but returns a ``py.path.local`` object.
- """
+ """Same as :meth:`TempPathFactory.mkdir`, but returns a ``py.path.local`` object."""
return py.path.local(self._tmppath_factory.mktemp(basename, numbered).resolve())
def getbasetemp(self) -> py.path.local:
- """backward compat wrapper for ``_tmppath_factory.getbasetemp``"""
+ """Backward compat wrapper for ``_tmppath_factory.getbasetemp``."""
return py.path.local(self._tmppath_factory.getbasetemp().resolve())
def get_user() -> Optional[str]:
"""Return the current user name, or None if getuser() does not work
- in the current environment (see #1010).
- """
+ in the current environment (see #1010)."""
import getpass
try:
@@ -153,16 +147,14 @@ def pytest_configure(config: Config) -> None:
@pytest.fixture(scope="session")
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory:
- """Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
- """
+ """Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session."""
# Set dynamically by pytest_configure() above.
return request.config._tmpdirhandler # type: ignore
@pytest.fixture(scope="session")
def tmp_path_factory(request: FixtureRequest) -> TempPathFactory:
- """Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
- """
+ """Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session."""
# Set dynamically by pytest_configure() above.
return request.config._tmp_path_factory # type: ignore
@@ -177,11 +169,11 @@ def _mk_tmp(request: FixtureRequest, factory: TempPathFactory) -> Path:
@pytest.fixture
def tmpdir(tmp_path: Path) -> py.path.local:
- """Return a temporary directory path object
- which is unique to each test function invocation,
- created as a sub directory of the base temporary
- directory. The returned object is a `py.path.local`_
- path object.
+ """Return a temporary directory path object which is unique to each test
+ function invocation, created as a sub directory of the base temporary
+ directory.
+
+ The returned object is a `py.path.local`_ path object.
.. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html
"""
@@ -190,15 +182,15 @@ def tmpdir(tmp_path: Path) -> py.path.local:
@pytest.fixture
def tmp_path(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Path:
- """Return a temporary directory path object
- which is unique to each test function invocation,
- created as a sub directory of the base temporary
- directory. The returned object is a :class:`pathlib.Path`
- object.
+ """Return a temporary directory path object which is unique to each test
+ function invocation, created as a sub directory of the base temporary
+ directory.
+
+ The returned object is a :class:`pathlib.Path` object.
.. note::
- in python < 3.6 this is a pathlib2.Path
+ In python < 3.6 this is a pathlib2.Path.
"""
return _mk_tmp(request, tmp_path_factory)