Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_pytest._argcomplete.FastFilesCompleter fails when no prefix specified #2748

evanunderscore opened this Issue Sep 2, 2017 · 4 comments


None yet
4 participants
Copy link

evanunderscore commented Sep 2, 2017

The overall effect of this is that pytest <tab> ends up using bash's default completer which completes just the files (no flags). This can be fixed by modifying the offending line to check if the prefix is non-empty, but I'm not sure if the current behavior (when _ARC_DEBUG is unset) actually desired.

To fix this and retain the current behavior, you could also modify try_argcomplete to call argcomplete.autocomplete(parser, always_complete_options=False).

$ export _ARC_DEBUG=1
$ pytest <tab>
[Trimmed argcomplete debug output]
Traceback (most recent call last):
  File "/usr/bin/pytest", line 11, in <module>
  File "/usr/lib/python2.7/site-packages/_pytest/", line 49, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python2.7/site-packages/_pytest/", line 168, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 250, in _wrapped_call
  File "/usr/lib/python2.7/site-packages/_pytest/", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 280, in get_result
    _reraise(*ex)  # noqa
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 265, in __init__
    self.result = func()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/", line 614, in execute
    res = hook_impl.function(*args)
  File "/usr/lib/python2.7/site-packages/_pytest/", line 957, in pytest_cmdline_parse
  File "/usr/lib/python2.7/site-packages/_pytest/", line 1126, in parse
    args = self._parser.parse_setoption(args, self.option, namespace=self.option)
  File "/usr/lib/python2.7/site-packages/_pytest/", line 562, in parse_setoption
    parsedoption = self.parse(args, namespace=namespace)
  File "/usr/lib/python2.7/site-packages/_pytest/", line 542, in parse
  File "/usr/lib/python2.7/site-packages/_pytest/", line 101, in try_argcomplete
  File "/usr/lib/python2.7/site-packages/argcomplete/", line 218, in __call__
    completions = self._get_completions(comp_words, cword_prefix, cword_prequote, last_wordbreak_pos)
  File "/usr/lib/python2.7/site-packages/argcomplete/", line 248, in _get_completions
    completions = self.collect_completions(active_parsers, parsed_args, cword_prefix, debug)
  File "/usr/lib/python2.7/site-packages/argcomplete/", line 461, in collect_completions
  File "/usr/lib/python2.7/site-packages/argcomplete/", line 415, in _complete_active_option
    prefix=cword_prefix, action=active_action, parser=parser, parsed_args=parsed_args)
  File "/usr/lib/python2.7/site-packages/_pytest/", line 81, in __call__
    if prefix[-1] == os.path.sep:  # we are on unix, otherwise no bash
IndexError: string index out of range

I'm using pytest 3.2.1.

(Be aware that kislyuk/argcomplete#225 may impact your ability to test this if you have installed pytest from a wheel.)


This comment has been minimized.

Copy link

nicoddemus commented Sep 2, 2017

Thanks @evanunderscore, would you like to open a PR with a fix?


This comment has been minimized.

Copy link
Contributor Author

evanunderscore commented Sep 3, 2017

Sure, although I need someone to decide whether to suggest flags when there is no prefix.


$ pytest <tab><tab>
bar  baz  foo


$ pytest <tab><tab>
--assert                         --disable-warnings               --help                           --noconftest                     --setuponly
bar                              --doctest-glob                   --ignore                         -o                               --setup-only
--basetemp                       --doctest-ignore-import-errors   --import-mode                    --override-ini                   --setupplan
baz                              --doctest-modules                --junitprefix                    -p                               --setup-plan
-c                               --doctest-report                 --junit-prefix                   --pastebin                       --setupshow
--cache-clear                    --durations                      --junitxml                       --pdb                            --setup-show
--cache-show                     --exitfirst                      --junit-xml                      --pdbcls                         --showlocals
--capture                        --failed-first                   -k                               --pyargs                         --strict
--collect-in-virtualenv          --ff                             --keepduplicates                 --pythonwarnings                 --tb
--collectonly                    --fixtures                       --keep-duplicates                -q                               --traceconfig
--collect-only                   --fixtures-per-test              -l                               --quiet                          --trace-config
--color                          foo                              --last-failed                    -r                               -v
--confcutdir                     --fulltrace                      --lf                             --resultlog                      --verbose
--continue-on-collection-errors  --full-trace                     -m                               --result-log                     --version
--debug                          --funcargs                       --markers                        --runxfail                       -W
--disable-pytest-warnings        -h                               --maxfail                        -s                               -x

Alternate fixed:

$ pytest <tab><tab>
bar  baz  foo

This comment has been minimized.

Copy link

pavelrad commented Sep 4, 2017

argcomplete suggests flags too when there is no prefix, and this looks right, as you can use flags as well as paths/positional args in any order. But in this case, it makes sense to sort positional args after (or before) flags. But curl, git, bash, ping, for example, don't suggest options until you put a dash in command and this seems to be a best practice in Linux command-line tools.


This comment has been minimized.

Copy link

RonnyPfannschmidt commented Sep 4, 2017

i believe for now we should simply try to keep current pytest behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.