Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/14080.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix missing type annotations on ``Pytester.makepyfile`` and ``Pytester.maketxtfile`` methods.
10 changes: 7 additions & 3 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Iterable
from collections.abc import Mapping
from collections.abc import Sequence
import contextlib
from fnmatch import fnmatch
Expand Down Expand Up @@ -645,6 +646,9 @@ def restore(self) -> None:
sys.path[:], sys.meta_path[:] = self.__saved


_FileContent = tuple[str | bytes, ...] | list[str | bytes] | str | bytes


@final
class Pytester:
"""
Expand Down Expand Up @@ -756,7 +760,7 @@ def _makefile(
self,
ext: str,
lines: Sequence[Any | bytes],
files: dict[str, str],
files: Mapping[str, _FileContent],
encoding: str = "utf-8",
) -> Path:
items = list(files.items())
Expand Down Expand Up @@ -862,7 +866,7 @@ def makepyprojecttoml(self, source: str) -> Path:
"""
return self.makefile(".toml", pyproject=source)

def makepyfile(self, *args, **kwargs) -> Path:
def makepyfile(self, *args: _FileContent, **kwargs: _FileContent) -> Path:
r"""Shortcut for .makefile() with a .py extension.

Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting
Expand All @@ -882,7 +886,7 @@ def test_something(pytester):
"""
return self._makefile(".py", args, kwargs)

def maketxtfile(self, *args, **kwargs) -> Path:
def maketxtfile(self, *args: _FileContent, **kwargs: _FileContent) -> Path:
r"""Shortcut for .makefile() with a .txt extension.

Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting
Expand Down