diff --git a/tests/run-tests.py b/tests/run-tests.py
index a4ec7a92d2c5233feb0aa07fdcb8d687246da2df_dGVzdHMvcnVuLXRlc3RzLnB5..afb3cccc90f73d9052257fbbce1a4f458256a0a7_dGVzdHMvcnVuLXRlc3RzLnB5 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3148,6 +3148,13 @@
         self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin')
         os.makedirs(self._custom_bin_dir)
 
+        # detect and enforce an alternative way to specify rust extension usage
+        if (
+            not (self.options.pure or self.options.rust or self.options.no_rust)
+            and os.environ.get("HGWITHRUSTEXT") == "cpython"
+        ):
+            self.options.rust = True
+
         if self.options.with_hg:
             self._installdir = None
             whg = self.options.with_hg