diff --git a/_pytest/_argcomplete.py b/_pytest/_argcomplete.py index 1ba1ecc1e..965ec7951 100644 --- a/_pytest/_argcomplete.py +++ b/_pytest/_argcomplete.py @@ -78,7 +78,8 @@ class FastFilesCompleter: completion = [] globbed = [] if '*' not in prefix and '?' not in prefix: - if prefix[-1] == os.path.sep: # we are on unix, otherwise no bash + # we are on unix, otherwise no bash + if not prefix or prefix[-1] == os.path.sep: globbed.extend(glob(prefix + '.*')) prefix += '*' globbed.extend(glob(prefix)) @@ -98,7 +99,7 @@ if os.environ.get('_ARGCOMPLETE'): filescompleter = FastFilesCompleter() def try_argcomplete(parser): - argcomplete.autocomplete(parser) + argcomplete.autocomplete(parser, always_complete_options=False) else: def try_argcomplete(parser): pass diff --git a/changelog/2748.bugfix b/changelog/2748.bugfix new file mode 100644 index 000000000..b5b6f5839 --- /dev/null +++ b/changelog/2748.bugfix @@ -0,0 +1 @@ +Fix crash in tab completion when no prefix is given. diff --git a/testing/test_argcomplete.py b/testing/test_argcomplete.py index b07f6e83b..c92612577 100644 --- a/testing/test_argcomplete.py +++ b/testing/test_argcomplete.py @@ -82,7 +82,7 @@ class TestArgComplete(object): from _pytest._argcomplete import FastFilesCompleter ffc = FastFilesCompleter() fc = FilesCompleter() - for x in '/ /d /data qqq'.split(): + for x in ['/', '/d', '/data', 'qqq', '']: assert equal_with_bash(x, ffc, fc, out=py.std.sys.stdout) @pytest.mark.skipif("sys.platform in ('win32', 'darwin')")