Change !() to also capture background subprocesses (#4406)

* Change !() to also capture background subprocesses

* Add test

* Add news

* Simplify logic
This commit is contained in:
Peter Ye 2021-08-01 14:58:19 -04:00 committed by GitHub
parent f5acbe30d4
commit d08006b0e0
Failed to generate hash of commit
3 changed files with 45 additions and 6 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* Changed !() to also capture background subprocesses
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -102,6 +102,23 @@ def test_capture_always(capfd, thread_subprocs, capture_always):
assert exp in capfd.readouterr().out
@skip_if_on_windows
@pytest.mark.parametrize(
"captured, exp_is_none",
[
("object", False),
("stdout", True),
("hiddenobject", True),
(False, True),
],
)
def test_run_subproc_background(captured, exp_is_none):
cmds = (["echo", "hello"], "&")
return_val = run_subproc(cmds, captured)
assert (return_val is None) == exp_is_none
@pytest.mark.parametrize("thread_subprocs", [False, True])
def test_callable_alias_cls(thread_subprocs, xession):
class Cls:

View file

@ -892,15 +892,14 @@ def run_subproc(cmds, captured=False, envs=None):
# sure that the shell doesn't hang. This `pause_call_resume` invocation
# does this
pause_call_resume(proc, int)
# create command or return if backgrounding.
if background:
# now figure out what we should return
if captured == "object":
return command # object can be returned even if backgrounding
elif background:
return
# now figure out what we should return.
if captured == "stdout":
elif captured == "stdout":
command.end()
return command.output
elif captured == "object":
return command
elif captured == "hiddenobject":
command.end()
return command