diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7731f6bf120f27a73f2fdc4f8828a6512b35b3f0_LmdpdGxhYi1jaS55bWw=..024370a053114ed73c321ef148555fcf32e82f2e_LmdpdGxhYi1jaS55bWw= 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -46,7 +46,7 @@
     # need to install/update something.
     - pip3 install -r test-requirements.txt
     - pip3 freeze
-    - flake8 --exclude stub hgitaly hgext3rd
+    - flake8 --exclude stub hgitaly hgext3rd tests_with_gitaly
     - ./run-all-tests
 
 tests-current:
diff --git a/run-all-tests b/run-all-tests
index 7731f6bf120f27a73f2fdc4f8828a6512b35b3f0_cnVuLWFsbC10ZXN0cw==..024370a053114ed73c321ef148555fcf32e82f2e_cnVuLWFsbC10ZXN0cw== 100755
--- a/run-all-tests
+++ b/run-all-tests
@@ -1,2 +1,8 @@
 #!/bin/sh
+set -e
+
+COV_PKG_OPTIONS="--cov hgext3rd --cov hgitaly"
+if test -n "$GITALY_INSTALL_DIR"; then
+    COV_PKG_OPTIONS="$COV_PKG_OPTIONS --cov tests_with_gitaly"
+fi
 
@@ -2,3 +8,3 @@
 
-set -ue
+set -u
 
@@ -4,2 +10,6 @@
 
-pytest --doctest-modules --cov hgext3rd --cov hgitaly --cov-config=.coveragerc --cov-fail-under 100 -v $@
+pytest --doctest-modules \
+       $COV_PKG_OPTIONS \
+       --cov-config=.coveragerc \
+       --cov-fail-under 100 \
+       -v $@
diff --git a/tests_with_gitaly/__init__.py b/tests_with_gitaly/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..024370a053114ed73c321ef148555fcf32e82f2e_dGVzdHNfd2l0aF9naXRhbHkvX19pbml0X18ucHk=
--- /dev/null
+++ b/tests_with_gitaly/__init__.py
@@ -0,0 +1,49 @@
+# Copyright 2020 Georges Racinet <georges.racinet@octobus.net>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+import os
+from pathlib import Path
+
+import hgitaly
+import logging
+import subprocess
+
+logger = logging.getLogger(__name__)
+
+
+def gitaly_install_dir():  # pragma no cover
+    """Return an absolute Path object for the Gitaly source checkout to use.
+
+    The Gitaly sources must have been built.
+    This first version assumes we are in HDK context or that
+    the ``GITALY_INSTALL_DIR`` environment variable is set (typically in CI).
+    """
+    from_env = os.environ.get("GITALY_INSTALL_DIR")
+    if from_env is not None:
+        return Path(from_env).resolve()
+
+    hgitaly_clone = Path(hgitaly.__file__).resolve().parent.parent
+    hdk = hgitaly_clone.parent
+    install_dir = hdk / 'gitaly'
+    if install_dir.is_dir():
+        gitaly = (install_dir / 'gitaly')
+        if gitaly.is_file():
+            # startup costs about 0.15s. That's a lot, but it will
+            # make sure our skip is correct and it is useful to log the
+            # version number
+            version = subprocess.check_output((str(gitaly),
+                                               '-version')).decode()
+            assert 'Gitaly' in version
+            logger.info("Found %s at %s. Will lauch comparison tests "
+                        "of HGitaly with Gitaly", version, gitaly)
+            return install_dir
+
+
+GITALY_INSTALL_DIR = gitaly_install_dir()
+
+
+def gitaly_not_installed():
+    return GITALY_INSTALL_DIR is None