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

This commit is contained in:
Simon K 2020-05-23 15:27:06 +01:00 committed by GitHub
parent b38edec60f
commit 05c22ff823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 2 deletions

View File

@ -687,11 +687,41 @@ class Testdir:
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):