Skip to content

Commit 4fe016d

Browse files
committed
Added tmp_pathplus fixture to testing
1 parent 1ec3f5f commit 4fe016d

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

doc-source/api/testing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
=================================
44

55
.. automodule:: domdf_python_tools.testing
6+
7+
.. autofunction:: domdf_python_tools.testing.tmp_pathplus

domdf_python_tools/testing.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:__pkginfo__:
99
1010
.. versionadded:: 0.4.9
11+
1112
"""
1213
#
1314
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
@@ -33,6 +34,7 @@
3334
import random
3435
import sys
3536
from functools import lru_cache
37+
from pathlib import Path
3638
from typing import Any, Iterator, List, Optional, Sequence, Tuple, Union
3739

3840
# 3rd party
@@ -42,6 +44,7 @@
4244

4345
# this package
4446
from domdf_python_tools.doctools import PYPY
47+
from domdf_python_tools.paths import PathPlus
4548
from domdf_python_tools.utils import Len
4649
from domdf_python_tools.versions import Version
4750

@@ -316,3 +319,28 @@ def only_pypy(reason: str = "Only required on PyPy.") -> _pytest.mark.structures
316319
""" # noqa D400
317320

318321
return pytest.mark.skipif(condition=not PYPY, reason=reason)
322+
323+
324+
@pytest.fixture(scope="function")
325+
def tmp_pathplus(tmp_path: Path) -> PathPlus:
326+
"""
327+
328+
Pytest fixture that returns a temporary directory in the form of a
329+
:class:`~domdf_python_tools.paths.PathPlus` object.
330+
331+
The directory is unique to each test function invocation,
332+
created as a sub directory of the base temporary directory.
333+
334+
Use it as follows:
335+
336+
.. code-block:: python
337+
338+
pytest_plugins = ("domdf_python_tools.testing", )
339+
340+
def my_test(tmp_pathplus: PathPlus):
341+
assert True
342+
343+
.. versionadded:: 0.10.0
344+
"""
345+
346+
return PathPlus(tmp_path)

tests/test_testing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# stdlib
2+
import platform
23
import random
34
import re
45

@@ -7,6 +8,8 @@
78

89
# this package
910
from domdf_python_tools import testing
11+
from domdf_python_tools.paths import PathPlus
12+
from domdf_python_tools.testing import not_pypy
1013
from domdf_python_tools.utils import strtobool
1114

1215

@@ -124,3 +127,17 @@ def test_generate_falsy():
124127
]
125128

126129
assert list(testing.generate_falsy_values(ratio=.3)) == ['0', "no", "False", False]
130+
131+
132+
@not_pypy("Success")
133+
def test_not_pypy():
134+
if platform.python_implementation() == "PyPy":
135+
assert False
136+
137+
138+
pytest_plugins = ("domdf_python_tools.testing", )
139+
140+
141+
def test_tmp_pathplus(tmp_pathplus):
142+
assert isinstance(tmp_pathplus, PathPlus)
143+
assert tmp_pathplus.exists()

0 commit comments

Comments
 (0)