diff --git a/i3ipc/i3ipc.py b/i3ipc/i3ipc.py
index <HASH>..<HASH> 100644
--- a/i3ipc/i3ipc.py
+++ b/i3ipc/i3ipc.py
@@ -353,7 +353,7 @@ class Connection(object):
     _struct_header_size = struct.calcsize(_struct_header)
 
     def __init__(self, socket_path=None, auto_reconnect=False):
-        if not socket_path:
+        if not socket_path and os.environ.get("_I3IPC_TEST") is None:
             socket_path = os.environ.get("I3SOCK")
 
         if not socket_path:
diff --git a/run-tests.py b/run-tests.py
index <HASH>..<HASH> 100755
--- a/run-tests.py
+++ b/run-tests.py
@@ -109,6 +109,7 @@ def run_pytest(display):
     env = os.environ.copy()
     env['DISPLAY'] = ':%d' % display
     env['PYTHONPATH'] = './i3ipc'
+    env['_I3IPC_TEST'] = '1'
     subprocess.run([PYTEST], env=env)
Ignore I3SOCK during tests

When we use the new I3SOCK environment variable set by i3, it will
ignore the current DISPLAY which is required to run tests on the Xvfb
server when running in another display.