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

Closed
evanunderscore opened this issue Sep 2, 2017 · 4 comments
Closed

Comments

@evanunderscore
Copy link
Contributor

@evanunderscore 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>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 49, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 168, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/usr/lib/python2.7/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 280, in get_result
    _reraise(*ex)  # noqa
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/usr/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 957, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 1126, in parse
    args = self._parser.parse_setoption(args, self.option, namespace=self.option)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 562, in parse_setoption
    parsedoption = self.parse(args, namespace=namespace)
  File "/usr/lib/python2.7/site-packages/_pytest/config.py", line 542, in parse
    try_argcomplete(self.optparser)
  File "/usr/lib/python2.7/site-packages/_pytest/_argcomplete.py", line 101, in try_argcomplete
    argcomplete.autocomplete(parser)
  File "/usr/lib/python2.7/site-packages/argcomplete/__init__.py", 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/__init__.py", line 248, in _get_completions
    completions = self.collect_completions(active_parsers, parsed_args, cword_prefix, debug)
  File "/usr/lib/python2.7/site-packages/argcomplete/__init__.py", line 461, in collect_completions
    completions)
  File "/usr/lib/python2.7/site-packages/argcomplete/__init__.py", 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/_argcomplete.py", 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.)

@nicoddemus
Copy link
Member

@nicoddemus nicoddemus commented Sep 2, 2017

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

@evanunderscore
Copy link
Contributor Author

@evanunderscore evanunderscore commented Sep 3, 2017

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

Current:

$ pytest <tab><tab>
bar  baz  foo

Fixed:

$ 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

@pavelrad
Copy link

@pavelrad 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.

@RonnyPfannschmidt
Copy link
Member

@RonnyPfannschmidt 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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants