Skip to content

Commit 05c22ff

Browse files
authored
7154-Improve-testdir-documentation-on-makefiles (#7239)
1 parent b38edec commit 05c22ff

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/_pytest/pytester.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,41 @@ def getinicfg(self, source):
687687
return py.iniconfig.IniConfig(p)["pytest"]
688688

689689
def makepyfile(self, *args, **kwargs):
690-
"""Shortcut for .makefile() with a .py extension."""
690+
r"""Shortcut for .makefile() with a .py extension.
691+
Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting
692+
existing files.
693+
694+
Examples:
695+
696+
.. code-block:: python
697+
698+
def test_something(testdir):
699+
# initial file is created test_something.py
700+
testdir.makepyfile("foobar")
701+
# to create multiple files, pass kwargs accordingly
702+
testdir.makepyfile(custom="foobar")
703+
# at this point, both 'test_something.py' & 'custom.py' exist in the test directory
704+
705+
"""
691706
return self._makefile(".py", args, kwargs)
692707

693708
def maketxtfile(self, *args, **kwargs):
694-
"""Shortcut for .makefile() with a .txt extension."""
709+
r"""Shortcut for .makefile() with a .txt extension.
710+
Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting
711+
existing files.
712+
713+
Examples:
714+
715+
.. code-block:: python
716+
717+
def test_something(testdir):
718+
# initial file is created test_something.txt
719+
testdir.maketxtfile("foobar")
720+
# to create multiple files, pass kwargs accordingly
721+
testdir.maketxtfile(custom="foobar")
722+
# at this point, both 'test_something.txt' & 'custom.txt' exist in the test directory
723+
724+
"""
695725
return self._makefile(".txt", args, kwargs)
696726

697727
def syspathinsert(self, path=None):

0 commit comments

Comments
 (0)