Skip to content

Commit daa11ab

Browse files
authored
Merge pull request #7930 from bluetech/pytester-doc-fixes
pytester: minor doc fixes
2 parents 0b14350 + 1c0c56d commit daa11ab

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/_pytest/pytester.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,9 @@ def makefile(self, ext: str, *args: str, **kwargs: str) -> Path:
771771
772772
.. code-block:: python
773773
774-
testdir.makefile(".txt", "line1", "line2")
774+
pytester.makefile(".txt", "line1", "line2")
775775
776-
testdir.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")
776+
pytester.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")
777777
778778
"""
779779
return self._makefile(ext, args, kwargs)
@@ -808,11 +808,11 @@ def makepyfile(self, *args, **kwargs) -> Path:
808808
809809
.. code-block:: python
810810
811-
def test_something(testdir):
811+
def test_something(pytester):
812812
# Initial file is created test_something.py.
813-
testdir.makepyfile("foobar")
813+
pytester.makepyfile("foobar")
814814
# To create multiple files, pass kwargs accordingly.
815-
testdir.makepyfile(custom="foobar")
815+
pytester.makepyfile(custom="foobar")
816816
# At this point, both 'test_something.py' & 'custom.py' exist in the test directory.
817817
818818
"""
@@ -828,11 +828,11 @@ def maketxtfile(self, *args, **kwargs) -> Path:
828828
829829
.. code-block:: python
830830
831-
def test_something(testdir):
831+
def test_something(pytester):
832832
# Initial file is created test_something.txt.
833-
testdir.maketxtfile("foobar")
833+
pytester.maketxtfile("foobar")
834834
# To create multiple files, pass kwargs accordingly.
835-
testdir.maketxtfile(custom="foobar")
835+
pytester.maketxtfile(custom="foobar")
836836
# At this point, both 'test_something.txt' & 'custom.txt' exist in the test directory.
837837
838838
"""
@@ -1279,15 +1279,15 @@ def popen(
12791279
)
12801280
kw["env"] = env
12811281

1282-
if stdin is Testdir.CLOSE_STDIN:
1282+
if stdin is self.CLOSE_STDIN:
12831283
kw["stdin"] = subprocess.PIPE
12841284
elif isinstance(stdin, bytes):
12851285
kw["stdin"] = subprocess.PIPE
12861286
else:
12871287
kw["stdin"] = stdin
12881288

12891289
popen = subprocess.Popen(cmdargs, stdout=stdout, stderr=stderr, **kw)
1290-
if stdin is Testdir.CLOSE_STDIN:
1290+
if stdin is self.CLOSE_STDIN:
12911291
assert popen.stdin is not None
12921292
popen.stdin.close()
12931293
elif isinstance(stdin, bytes):
@@ -1311,7 +1311,7 @@ def run(
13111311
being converted to ``str`` automatically.
13121312
:param timeout:
13131313
The period in seconds after which to timeout and raise
1314-
:py:class:`Testdir.TimeoutExpired`.
1314+
:py:class:`Pytester.TimeoutExpired`.
13151315
:param stdin:
13161316
Optional standard input. Bytes are being send, closing
13171317
the pipe, otherwise it is passed through to ``popen``.
@@ -1412,7 +1412,7 @@ def runpytest_subprocess(self, *args, timeout: Optional[float] = None) -> RunRes
14121412
The sequence of arguments to pass to the pytest subprocess.
14131413
:param timeout:
14141414
The period in seconds after which to timeout and raise
1415-
:py:class:`Testdir.TimeoutExpired`.
1415+
:py:class:`Pytester.TimeoutExpired`.
14161416
14171417
:rtype: RunResult
14181418
"""
@@ -1453,9 +1453,8 @@ def spawn(self, cmd: str, expect_timeout: float = 10.0) -> "pexpect.spawn":
14531453
pytest.skip("pexpect.spawn not available")
14541454
logfile = self.path.joinpath("spawn.out").open("wb")
14551455

1456-
child = pexpect.spawn(cmd, logfile=logfile)
1456+
child = pexpect.spawn(cmd, logfile=logfile, timeout=expect_timeout)
14571457
self._request.addfinalizer(logfile.close)
1458-
child.timeout = expect_timeout
14591458
return child
14601459

14611460

0 commit comments

Comments
 (0)