Skip to content

7154-Improve-testdir-documentation-on-makefiles #7239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
34 changes: 32 additions & 2 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,41 @@ def getinicfg(self, source):
return py.iniconfig.IniConfig(p)["pytest"]

def makepyfile(self, *args, **kwargs):
"""Shortcut for .makefile() with a .py extension."""
r"""Shortcut for .makefile() with a .py extension.
Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting
existing files.

Examples:

.. code-block:: python

def test_something(testdir):
# initial file is created test_something.py
testdir.makepyfile("foobar")
# to create multiple files, pass kwargs accordingly
testdir.makepyfile(custom="foobar")
# at this point, both 'test_something.py' & 'custom.py' exist in the test directory

"""
return self._makefile(".py", args, kwargs)

def maketxtfile(self, *args, **kwargs):
"""Shortcut for .makefile() with a .txt extension."""
r"""Shortcut for .makefile() with a .txt extension.
Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting
existing files.

Examples:

.. code-block:: python

def test_something(testdir):
# initial file is created test_something.txt
testdir.maketxtfile("foobar")
# to create multiple files, pass kwargs accordingly
testdir.maketxtfile(custom="foobar")
# at this point, both 'test_something.txt' & 'custom.txt' exist in the test directory

"""
return self._makefile(".txt", args, kwargs)

def syspathinsert(self, path=None):
Expand Down