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
--- 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