Skip to content

Commit b67b1cc

Browse files
committed
fixup! pytester: testdir: add makefiles helper
1 parent f6de998 commit b67b1cc

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/_pytest/pytester.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,15 @@ def maketxtfile(self, *args, **kwargs):
666666
"""Shortcut for .makefile() with a .txt extension."""
667667
return self._makefile(".txt", args, kwargs)
668668

669-
def makefiles(self, **kwargs: str) -> Optional[Path]:
669+
def makefiles(self, **kwargs: str) -> List[Path]:
670670
"""Create the given set of files."""
671-
first_path = None
671+
paths = []
672672
for fname, content in kwargs.items():
673673
path = Path(self.tmpdir).joinpath(Path(fname))
674674
with open(path, "w") as fp:
675675
fp.write(textwrap.dedent(content))
676-
if not first_path:
677-
first_path = path
678-
return first_path
676+
paths.append(path)
677+
return paths
679678

680679
def syspathinsert(self, path=None):
681680
"""Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`.

testing/test_pytester.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,15 @@ def test_error2(bad_fixture):
715715

716716
def test_testdir_makefiles(testdir: Testdir) -> None:
717717
abspath = str(testdir.tmpdir / "bar")
718-
p1 = testdir.makefiles(**{"foo": "", abspath: ""})
718+
created_paths = testdir.makefiles(**{"foo": "", abspath: ""})
719+
p1 = created_paths[0]
720+
assert isinstance(p1, Path)
719721
relpath = testdir.tmpdir / "foo"
720722
assert p1 == relpath
721723

724+
assert str(created_paths[1]) == abspath
722725
abspath_path = Path(abspath)
723726
assert abspath_path.exists()
724727
assert str(abspath_path) == abspath
725728

726-
assert testdir.makefiles() is None
729+
assert testdir.makefiles() == []

0 commit comments

Comments
 (0)