-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
I am getting a ValueError
when using CliRunner
to test my CLI tool. Unfortunately I can't isolate, but I can give a reproduction:
pip install git+git://github.com/ResidentMario/datablocks.git@d6601c8321e7fb050bb62760067dc63ca4600003
pip install pytest
cd datablocks/tests
pytest cli_tests.py
Which raises the following traceback:
=================================== FAILURES ===================================
_________________________ TestLink.test_depositor_link _________________________
self = <cli_tests.TestLink testMethod=test_depositor_link>
def test_depositor_link(self):
> result = runner.invoke(cli.link, ["test_depositor.py", "--outputs", "['bar2.txt']"])
cli_tests.py:41:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <click.testing.CliRunner object at 0x7f2c833a6cc0>
cli = <click.core.Command object at 0x7f2c82e7a5f8>
args = ['test_depositor.py', '--outputs', "['bar2.txt']"], input = None
env = None, catch_exceptions = True, color = False, extra = {}
exc_info = (<class 'SystemExit'>, SystemExit(0,), <traceback object at 0x7f2c82e1eb08>)
out = <_io.BytesIO object at 0x7f2c82e0a5c8>, exception = None, exit_code = 0
def invoke(self, cli, args=None, input=None, env=None,
catch_exceptions=True, color=False, **extra):
"""Invokes a command in an isolated environment. The arguments are
forwarded directly to the command line script, the `extra` keyword
arguments are passed to the :meth:`~clickpkg.Command.main` function of
the command.
This returns a :class:`Result` object.
.. versionadded:: 3.0
The ``catch_exceptions`` parameter was added.
.. versionchanged:: 3.0
The result object now has an `exc_info` attribute with the
traceback if available.
.. versionadded:: 4.0
The ``color`` parameter was added.
:param cli: the command to invoke
:param args: the arguments to invoke
:param input: the input data for `sys.stdin`.
:param env: the environment overrides.
:param catch_exceptions: Whether to catch any other exceptions than
``SystemExit``.
:param extra: the keyword arguments to pass to :meth:`main`.
:param color: whether the output should contain color codes. The
application can still override this explicitly.
"""
exc_info = None
with self.isolation(input=input, env=env, color=color) as out:
exception = None
exit_code = 0
try:
cli.main(args=args or (),
prog_name=self.get_default_prog_name(cli), **extra)
except SystemExit as e:
if e.code != 0:
exception = e
exc_info = sys.exc_info()
exit_code = e.code
if not isinstance(exit_code, int):
sys.stdout.write(str(exit_code))
sys.stdout.write('\n')
exit_code = 1
except Exception as e:
if not catch_exceptions:
raise
exception = e
exit_code = -1
exc_info = sys.exc_info()
finally:
sys.stdout.flush()
> output = out.getvalue()
E ValueError: I/O operation on closed file.
../../../miniconda3/envs/datablocks-dev/lib/python3.6/site-packages/click/testing.py:299: ValueError
========================== 1 failed in 37.10 seconds ===========================
This is on Ubuntu 16.04.
JarnoRFB, rauerhans, mboutet, alissa-huskey, gador and 9 morethomasleveil, jwillis0720, juftin and bodograumann