mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
cli: Fake fdopen to work around argcomplete bug with pytest
argcomplete will uncontionally try to take over fd=9 which causes problems with pytest capturing Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
247170c066
commit
4f15e2d6eb
@ -556,6 +556,7 @@ def autocomplete(parser):
|
|||||||
return
|
return
|
||||||
|
|
||||||
import argcomplete
|
import argcomplete
|
||||||
|
import unittest.mock
|
||||||
|
|
||||||
parsernames = [pclass.cli_flag_name() for pclass in
|
parsernames = [pclass.cli_flag_name() for pclass in
|
||||||
_get_completer_parsers()]
|
_get_completer_parsers()]
|
||||||
@ -572,13 +573,22 @@ def autocomplete(parser):
|
|||||||
kwargs["output_stream"] = io.BytesIO()
|
kwargs["output_stream"] = io.BytesIO()
|
||||||
kwargs["exit_method"] = sys.exit
|
kwargs["exit_method"] = sys.exit
|
||||||
|
|
||||||
try:
|
# This fdopen hackery is to avoid argcomplete debug_stream behavior
|
||||||
argcomplete.autocomplete(parser, **kwargs)
|
# from taking over an fd that pytest wants to use
|
||||||
except SystemExit:
|
fake_fdopen = os.fdopen
|
||||||
if in_testsuite():
|
if in_testsuite():
|
||||||
output = kwargs["output_stream"].getvalue().decode("utf-8")
|
def fake_fdopen_cb(*args, **kwargs):
|
||||||
print(output)
|
return sys.stderr
|
||||||
raise
|
fake_fdopen = fake_fdopen_cb
|
||||||
|
|
||||||
|
with unittest.mock.patch.object(os, "fdopen", fake_fdopen):
|
||||||
|
try:
|
||||||
|
argcomplete.autocomplete(parser, **kwargs)
|
||||||
|
except SystemExit:
|
||||||
|
if in_testsuite():
|
||||||
|
output = kwargs["output_stream"].getvalue().decode("utf-8")
|
||||||
|
print(output)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
Loading…
Reference in New Issue
Block a user