Skip to content
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
27 changes: 13 additions & 14 deletions src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,9 @@ def makefile(self, ext: str, *args: str, **kwargs: str) -> Path:

.. code-block:: python

testdir.makefile(".txt", "line1", "line2")
pytester.makefile(".txt", "line1", "line2")

testdir.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")
pytester.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")

"""
return self._makefile(ext, args, kwargs)
Expand Down Expand Up @@ -808,11 +808,11 @@ def makepyfile(self, *args, **kwargs) -> Path:

.. code-block:: python

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

"""
Expand All @@ -828,11 +828,11 @@ def maketxtfile(self, *args, **kwargs) -> Path:

.. code-block:: python

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

"""
Expand Down Expand Up @@ -1279,15 +1279,15 @@ def popen(
)
kw["env"] = env

if stdin is Testdir.CLOSE_STDIN:
if stdin is self.CLOSE_STDIN:
kw["stdin"] = subprocess.PIPE
elif isinstance(stdin, bytes):
kw["stdin"] = subprocess.PIPE
else:
kw["stdin"] = stdin

popen = subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
if stdin is Testdir.CLOSE_STDIN:
if stdin is self.CLOSE_STDIN:
assert popen.stdin is not None
popen.stdin.close()
elif isinstance(stdin, bytes):
Expand All @@ -1311,7 +1311,7 @@ def run(
being converted to ``str`` automatically.
:param timeout:
The period in seconds after which to timeout and raise
:py:class:`Testdir.TimeoutExpired`.
:py:class:`Pytester.TimeoutExpired`.
:param stdin:
Optional standard input. Bytes are being send, closing
the pipe, otherwise it is passed through to ``popen``.
Expand Down Expand Up @@ -1412,7 +1412,7 @@ def runpytest_subprocess(self, *args, timeout: Optional[float] = None) -> RunRes
The sequence of arguments to pass to the pytest subprocess.
:param timeout:
The period in seconds after which to timeout and raise
:py:class:`Testdir.TimeoutExpired`.
:py:class:`Pytester.TimeoutExpired`.

:rtype: RunResult
"""
Expand Down Expand Up @@ -1453,9 +1453,8 @@ def spawn(self, cmd: str, expect_timeout: float = 10.0) -> "pexpect.spawn":
pytest.skip("pexpect.spawn not available")
logfile = self.path.joinpath("spawn.out").open("wb")

child = pexpect.spawn(cmd, logfile=logfile)
child = pexpect.spawn(cmd, logfile=logfile, timeout=expect_timeout)
self._request.addfinalizer(logfile.close)
child.timeout = expect_timeout
return child


Expand Down