Bug 1390699 - Use same logic as `subprocess.Popen` to find echo. draft
authorTom Prince <mozilla@hocat.ca>
Thu, 17 Aug 2017 01:06:26 -0600
changeset 648084 b1c8db753d3cd20b12184c3097fab21d9f4d34cc
parent 648046 932388b8c22c9775264e543697ce918415db9e23
child 726697 5c0e1fcab69618157e60bb425edcc6b674e0ebc6
push id74616
push userbmo:mozilla@hocat.ca
push dateThu, 17 Aug 2017 07:14:05 +0000
bugs1390699
milestone57.0a1
Bug 1390699 - Use same logic as `subprocess.Popen` to find echo. On Windows, `subprocess.Popen` uses `CreateProcess` to spawn programs. If the executable name provided doesn't have an extension or path, Windows will add `.exe` and then search `PATH`. `py.path.local.sysfind` will search for the exact executable name, as well as with any extension in `PATHEXT` (this behavior matches that of `cmd.exe`). `distutils.spawn.find_executable` instead uses the same behavior as `CreateProcess`. MozReview-Commit-ID: CBbdHUoIWvN
python/mozlint/test/test_cli.py
--- a/python/mozlint/test/test_cli.py
+++ b/python/mozlint/test/test_cli.py
@@ -1,16 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 import sys
+from distutils.spawn import find_executable
 
-import py
 import pytest
 
 from mozlint import cli
 
 here = os.path.abspath(os.path.dirname(__file__))
 
 
 @pytest.fixture
@@ -34,17 +34,17 @@ def run(parser, lintdir, files):
 
 def test_cli_run_with_fix(run, capfd):
     ret = run(['-f', 'json', '--fix', '--linter', 'external'])
     out, err = capfd.readouterr()
     assert ret == 0
     assert out.endswith('{}\n')
 
 
-@pytest.mark.skipif(not py.path.local.sysfind("echo"), reason="No `echo` executable found.")
+@pytest.mark.skipif(not find_executable("echo"), reason="No `echo` executable found.")
 def test_cli_run_with_edit(run, parser, capfd):
     os.environ['EDITOR'] = 'echo'
 
     ret = run(['-f', 'compact', '--edit', '--linter', 'external'])
     out, err = capfd.readouterr()
     out = out.splitlines()
     assert ret == 1
     assert len(out) == 5