diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -553,7 +553,7 @@ def has_root():
 @check("pyflakes", "Pyflakes python linter")
 def has_pyflakes():
     return matchoutput(
-        "sh -c \"echo 'import re' 2>&1 | pyflakes\"",
+        "sh -c \"echo 'import re' 2>&1 | $PYTHON -m pyflakes\"",
         br"<stdin>:1: 're' imported but unused",
         True,
     )
diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
--- a/tests/test-check-pyflakes.t
+++ b/tests/test-check-pyflakes.t
@@ -20,7 +20,7 @@ run pyflakes on all tracked files ending
   > -X mercurial/thirdparty/concurrent \
   > -X mercurial/thirdparty/zope \
   > 2>/dev/null \
-  > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
+  > | xargs $PYTHON -m pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
   contrib/perf.py:*: undefined name 'xrange' (glob) (?)
   mercurial/hgweb/server.py:*: undefined name 'reload' (glob) (?)
   mercurial/util.py:*: undefined name 'file' (glob) (?)