diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -29,7 +29,8 @@
 stdout = getattr(sys.stdout, 'buffer', sys.stdout)
 stderr = getattr(sys.stderr, 'buffer', sys.stderr)
 
-if sys.version_info[0] >= 3:
+is_not_python2 = sys.version_info[0] >= 3
+if is_not_python2:
 
     def _sys2bytes(p):
         if p is None:
@@ -169,6 +170,8 @@
 
 @check("bzr", "Canonical's Bazaar client")
 def has_bzr():
+    if not is_not_python2:
+        return False
     try:
         import bzrlib
         import bzrlib.bzrdir