diff options
author | bengartner <gartner@gmail.com> | 2021-01-04 07:58:11 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 15:58:11 +0200 |
commit | 8e00df4c4b62f08df0003e578c581e0b5728e571 (patch) | |
tree | 2a4034d12d0ec688bf8eaba1c9a23cc528fd1187 /src/_pytest | |
parent | 8d16bec3297aed652bf0c3ad5835499e793c456f (diff) | |
download | pytest-8e00df4c4b62f08df0003e578c581e0b5728e571.tar.gz |
Add dot prefix if file makefile extension is invalid for pathlib (#8222)
Diffstat (limited to 'src/_pytest')
-rw-r--r-- | src/_pytest/pytester.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 4544d2c2b..95b22b3b2 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -64,6 +64,7 @@ from _pytest.reports import TestReport from _pytest.tmpdir import TempPathFactory from _pytest.warning_types import PytestWarning + if TYPE_CHECKING: from typing_extensions import Literal @@ -750,6 +751,11 @@ class Pytester: ) -> Path: items = list(files.items()) + if ext and not ext.startswith("."): + raise ValueError( + f"pytester.makefile expects a file extension, try .{ext} instead of {ext}" + ) + def to_text(s: Union[Any, bytes]) -> str: return s.decode(encoding) if isinstance(s, bytes) else str(s) @@ -1559,6 +1565,14 @@ class Testdir: def makefile(self, ext, *args, **kwargs) -> py.path.local: """See :meth:`Pytester.makefile`.""" + if ext and not ext.startswith("."): + # pytester.makefile is going to throw a ValueError in a way that + # testdir.makefile did not, because + # pathlib.Path is stricter suffixes than py.path + # This ext arguments is likely user error, but since testdir has + # allowed this, we will prepend "." as a workaround to avoid breaking + # testdir usage that worked before + ext = "." + ext return py.path.local(str(self._pytester.makefile(ext, *args, **kwargs))) def makeconftest(self, source) -> py.path.local: |