Skip to content

Commit 6b81003

Browse files
authored
bpo-28624: Add a test that checks that cwd parameter of Popen() accepts PathLike objects (#157) (#323)
(cherry picked from commit d5c11f7)
1 parent deea29e commit 6b81003

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

Doc/library/subprocess.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,13 @@ functions.
466466
The *pass_fds* parameter was added.
467467

468468
If *cwd* is not ``None``, the function changes the working directory to
469-
*cwd* before executing the child. In particular, the function looks for
470-
*executable* (or for the first item in *args*) relative to *cwd* if the
471-
executable path is a relative path.
469+
*cwd* before executing the child. *cwd* can be a :class:`str` and
470+
:term:`path-like <path-like object>` object. In particular, the function
471+
looks for *executable* (or for the first item in *args*) relative to *cwd*
472+
if the executable path is a relative path.
473+
474+
.. versionchanged:: 3.6
475+
*cwd* parameter accepts a :term:`path-like object`.
472476

473477
If *restore_signals* is true (the default) all signals that Python has set to
474478
SIG_IGN are restored to SIG_DFL in the child process before the exec.

Lib/test/test_subprocess.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ def test_cwd(self):
347347
temp_dir = self._normalize_cwd(temp_dir)
348348
self._assert_cwd(temp_dir, sys.executable, cwd=temp_dir)
349349

350+
def test_cwd_with_pathlike(self):
351+
temp_dir = tempfile.gettempdir()
352+
temp_dir = self._normalize_cwd(temp_dir)
353+
354+
class _PathLikeObj:
355+
def __fspath__(self):
356+
return temp_dir
357+
358+
self._assert_cwd(temp_dir, sys.executable, cwd=_PathLikeObj())
359+
350360
@unittest.skipIf(mswindows, "pending resolution of issue #15533")
351361
def test_cwd_with_relative_arg(self):
352362
# Check that Popen looks for args[0] relative to cwd if args[0]

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ Albert Chin-A-Young
269269
Adal Chiriliuc
270270
Matt Chisholm
271271
Lita Cho
272+
Sayan Chowdhury
272273
Anders Chrigström
273274
Tom Christiansen
274275
Renee Chu

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Extension Modules
6969
Library
7070
-------
7171

72+
- bpo-28624: Add a test that checks that cwd parameter of Popen() accepts
73+
PathLike objects. Patch by Sayan Chowdhury.
74+
7275
- bpo-28518: Start a transaction implicitly before a DML statement.
7376
Patch by Aviv Palivoda.
7477

0 commit comments

Comments
 (0)