_pytest.tmpdir module¶
support for providing temporary directories to test functions.
-
class
TempPathFactory(given_basetemp, trace, basetemp: Optional[pathlib.Path] = None)[source]¶ Bases:
objectFactory for temporary directories under the common base temp directory.
The base directory can be configured using the
--basetempoption.-
classmethod
from_config(config) → _pytest.tmpdir.TempPathFactory[source]¶ - Parameters
config – a pytest configuration
-
mktemp(basename: str, numbered: bool = True) → pathlib.Path[source]¶ Creates a new temporary directory managed by the factory.
- Parameters
basename – Directory base name, must be a relative path.
numbered – If True, ensure the directory is unique by adding a number prefix greater than any existing one:
basename="foo"andnumbered=Truemeans that this function will create directories named"foo-0","foo-1","foo-2"and so on.
- Returns
The path to the new directory.
-
getbasetemp() → pathlib.Path[source]¶ return base temporary directory.
-
classmethod
-
class
TempdirFactory(tmppath_factory: _pytest.tmpdir.TempPathFactory)[source]¶ Bases:
objectbackward comptibility wrapper that implements :class:
py.path.localfor :class:TempPathFactory
-
get_user() → Optional[str][source]¶ Return the current user name, or None if getuser() does not work in the current environment (see #1010).
-
tmpdir_factory(tmp_path_factory) → _pytest.tmpdir.TempdirFactory[source]¶ Return a
_pytest.tmpdir.TempdirFactoryinstance for the test session.
-
tmp_path_factory(request: _pytest.fixtures.FixtureRequest) → _pytest.tmpdir.TempPathFactory[source]¶ Return a
_pytest.tmpdir.TempPathFactoryinstance for the test session.
-
_mk_tmp(request: _pytest.fixtures.FixtureRequest, factory: _pytest.tmpdir.TempPathFactory) → pathlib.Path[source]¶
-
tmpdir(tmp_path) → py._path.local.LocalPath[source]¶ 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.localobject.
-
tmp_path(request: _pytest.fixtures.FixtureRequest, tmp_path_factory: _pytest.tmpdir.TempPathFactory) → pathlib.Path[source]¶ 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
pathlib.Pathobject.Note
in python < 3.6 this is a pathlib2.Path