From e3a2e1bbf845604318fb003c4aedd4d12688354a Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 31 Jul 2013 16:03:53 +0200 Subject: [PATCH 1/2] fix for tests running subprocesses of py.test after test_argcomplete (which all still ran with argcompletion enabled) -> fail --HG-- branch : argcomplete --- testing/test_parseopt.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 3c7194c4d..db3a82521 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -176,7 +176,7 @@ def test_addoption_parser_epilog(testdir): @pytest.mark.skipif("sys.version_info < (2,5)") def test_argcomplete(testdir): if not py.path.local.sysfind('bash'): - pytest.skip("bash not available") + pytest.skip("bash not available") import os script = os.path.join(os.getcwd(), 'test_argcomplete') with open(str(script), 'w') as fp: @@ -185,6 +185,10 @@ def test_argcomplete(testdir): # so we use bash fp.write('COMP_WORDBREAKS="$COMP_WORDBREAKS" $(which py.test) ' '8>&1 9>&2') + # alternative would be exteneded Testdir.{run(),_run(),popen()} to be able + # to handle a keyword argument env that replaces os.environ in popen or + # extends the copy, advantage: could not forget to restore + orgenv = os.environ.copy() os.environ['_ARGCOMPLETE'] = "1" os.environ['_ARGCOMPLETE_IFS'] = "\x0b" os.environ['COMP_WORDBREAKS'] = ' \\t\\n"\\\'><=;|&(:' @@ -206,3 +210,5 @@ def test_argcomplete(testdir): os.environ['COMP_POINT'] = str(len(os.environ['COMP_LINE'])) result = testdir.run('bash', str(script), arg) result.stdout.fnmatch_lines(["test_argcomplete", "test_argcomplete.d/"]) + # restore environment + os.environ = orgenv.copy() From ef2ddb6f16d5118d6bf602af9c87e09bee456e39 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 31 Jul 2013 21:33:13 +0200 Subject: [PATCH 2/2] monkeypatch for os.environment changes --HG-- branch : argcomplete --- testing/test_parseopt.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index db3a82521..9d89e6d5b 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -174,7 +174,7 @@ def test_addoption_parser_epilog(testdir): result.stdout.fnmatch_lines(["hint: hello world", "hint: from me too"]) @pytest.mark.skipif("sys.version_info < (2,5)") -def test_argcomplete(testdir): +def test_argcomplete(testdir, monkeypatch): if not py.path.local.sysfind('bash'): pytest.skip("bash not available") import os @@ -188,14 +188,13 @@ def test_argcomplete(testdir): # alternative would be exteneded Testdir.{run(),_run(),popen()} to be able # to handle a keyword argument env that replaces os.environ in popen or # extends the copy, advantage: could not forget to restore - orgenv = os.environ.copy() - os.environ['_ARGCOMPLETE'] = "1" - os.environ['_ARGCOMPLETE_IFS'] = "\x0b" - os.environ['COMP_WORDBREAKS'] = ' \\t\\n"\\\'><=;|&(:' + monkeypatch.setenv('_ARGCOMPLETE', "1") + monkeypatch.setenv('_ARGCOMPLETE_IFS',"\x0b") + monkeypatch.setenv('COMP_WORDBREAKS', ' \\t\\n"\\\'><=;|&(:') arg = '--fu' - os.environ['COMP_LINE'] = "py.test " + arg - os.environ['COMP_POINT'] = str(len(os.environ['COMP_LINE'])) + monkeypatch.setenv('COMP_LINE', "py.test " + arg) + monkeypatch.setenv('COMP_POINT', str(len("py.test " + arg))) result = testdir.run('bash', str(script), arg) print dir(result), result.ret if result.ret == 255: @@ -206,9 +205,8 @@ def test_argcomplete(testdir): os.mkdir('test_argcomplete.d') arg = 'test_argc' - os.environ['COMP_LINE'] = "py.test " + arg - os.environ['COMP_POINT'] = str(len(os.environ['COMP_LINE'])) + monkeypatch.setenv('COMP_LINE', "py.test " + arg) + monkeypatch.setenv('COMP_POINT', str(len('py.test ' + arg))) result = testdir.run('bash', str(script), arg) result.stdout.fnmatch_lines(["test_argcomplete", "test_argcomplete.d/"]) # restore environment - os.environ = orgenv.copy()