mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Change !() to also capture background subprocesses (#4406)
* Change !() to also capture background subprocesses * Add test * Add news * Simplify logic
This commit is contained in:
parent
f5acbe30d4
commit
d08006b0e0
3 changed files with 45 additions and 6 deletions
23
news/capture-object-background.rst
Normal file
23
news/capture-object-background.rst
Normal 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>
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue