diff --git a/testenv/README b/testenv/README
index 6580bc99..aca8cdda 100644
--- a/testenv/README
+++ b/testenv/README
@@ -99,6 +99,10 @@ Environment Variables:
   If it is set to "1", valgrind memcheck is enabled with hard coded options.
   This variable is set by ./configure --enable-valgrind-tests.
 * SSL_TESTS: This must be set to run any https tests.
+* WGET_PATH: Set this environment variable to a path to wget binary on which you
+  want to run tests. This is useful for OS distributions, which want to reuse
+  upstream tests for testing wget build that they distribute. If the variable is
+  not set, the "../src/wget" binary is used by tests.
 
 
 File Structure:
diff --git a/testenv/test/base_test.py b/testenv/test/base_test.py
index 1e1eb181..dbf4678f 100644
--- a/testenv/test/base_test.py
+++ b/testenv/test/base_test.py
@@ -111,8 +111,12 @@ class BaseTest:
 
     def gen_cmd_line(self):
         test_path = os.path.abspath(".")
-        wget_path = os.path.abspath(os.path.join(test_path,
-                                                 "..", '..', 'src', "wget"))
+        if os.getenv("WGET_PATH"):
+            wget_path = os.path.abspath(os.getenv("WGET_PATH"))
+        else:
+            wget_path = os.path.abspath(os.path.join(test_path,
+                                                     "..", '..', 'src',
+                                                     "wget"))
         wget_options = '--debug --no-config %s' % self.wget_options
 
         valgrind = os.getenv("VALGRIND_TESTS", "")