@@ -36,6 +36,13 @@ def _restore_module_attrs(snapshot):
3636 else :
3737 setattr (module , name , value )
3838
39+
40+ def _set_loader_path (monkeypatch , install_dir ):
41+ if not sys .platform .startswith ("win" ):
42+ env_var = _iris_ep ._bootstrap .get_loader_path_env_var ()
43+ monkeypatch .setenv (env_var , str (install_dir / "bin" ))
44+
45+
3946def test_import_iris ():
4047 import iris
4148
@@ -101,6 +108,7 @@ def test_connect_path_enables_embedded_runtime(monkeypatch, tmp_path):
101108 (install_dir / "bin" ).mkdir (parents = True )
102109 (install_dir / "lib" / "python" ).mkdir (parents = True )
103110 dynalib_paths = []
111+ _set_loader_path (monkeypatch , install_dir )
104112
105113 class FakeVersion :
106114 @staticmethod
@@ -179,6 +187,7 @@ def test_connect_path_reports_loader_path_import_error(monkeypatch, tmp_path):
179187 (install_dir / "bin" ).mkdir (parents = True )
180188 (install_dir / "lib" / "python" ).mkdir (parents = True )
181189 dynalib_paths = []
190+ _set_loader_path (monkeypatch , install_dir )
182191
183192 def fake_import_module (name ):
184193 raise ImportError ("dlopen(pythonint.so): Library not loaded: libirisdb.dylib" )
@@ -196,13 +205,74 @@ def fake_import_module(name):
196205 iris .runtime .reset ()
197206
198207
208+ @pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "Unix loader-path warning" )
209+ def test_connect_path_warns_when_loader_path_missing (monkeypatch , tmp_path ):
210+ iris .runtime .reset ()
211+ install_dir = tmp_path / "iris"
212+ (install_dir / "bin" ).mkdir (parents = True )
213+ (install_dir / "lib" / "python" ).mkdir (parents = True )
214+ env_var = _iris_ep ._bootstrap .get_loader_path_env_var ()
215+ monkeypatch .delenv (env_var , raising = False )
216+
217+ fake_module = types .SimpleNamespace (
218+ __file__ = str (install_dir / "bin" / "pythonint.so" ),
219+ cls = lambda name : {"class" : name },
220+ connect = lambda * args , ** kwargs : {"ok" : True },
221+ )
222+
223+ def fake_import_module (name ):
224+ if name == "pythonint" :
225+ return fake_module
226+ raise ModuleNotFoundError (name )
227+
228+ monkeypatch .setattr (_iris_ep ._bootstrap .importlib , "import_module" , fake_import_module )
229+ monkeypatch .setattr (_iris_ep ._bootstrap , "update_dynalib_path" , lambda path : None )
230+
231+ with pytest .warns (RuntimeWarning , match = f"{ env_var } does not include" ):
232+ iris .connect (path = install_dir )
233+
234+ iris .runtime .reset ()
235+
236+
237+ @pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "Unix loader-path warning" )
238+ def test_connect_path_warns_when_loader_path_points_elsewhere (monkeypatch , tmp_path ):
239+ iris .runtime .reset ()
240+ install_dir = tmp_path / "iris"
241+ other_dir = tmp_path / "other"
242+ (install_dir / "bin" ).mkdir (parents = True )
243+ (install_dir / "lib" / "python" ).mkdir (parents = True )
244+ other_dir .mkdir ()
245+ env_var = _iris_ep ._bootstrap .get_loader_path_env_var ()
246+ monkeypatch .setenv (env_var , str (other_dir ))
247+
248+ fake_module = types .SimpleNamespace (
249+ __file__ = str (install_dir / "bin" / "pythonint.so" ),
250+ cls = lambda name : {"class" : name },
251+ connect = lambda * args , ** kwargs : {"ok" : True },
252+ )
253+
254+ def fake_import_module (name ):
255+ if name == "pythonint" :
256+ return fake_module
257+ raise ModuleNotFoundError (name )
258+
259+ monkeypatch .setattr (_iris_ep ._bootstrap .importlib , "import_module" , fake_import_module )
260+ monkeypatch .setattr (_iris_ep ._bootstrap , "update_dynalib_path" , lambda path : None )
261+
262+ with pytest .warns (RuntimeWarning , match = f"{ env_var } does not include" ):
263+ iris .connect (path = install_dir )
264+
265+ iris .runtime .reset ()
266+
267+
199268def test_connect_path_rejects_pythonint_from_other_install (monkeypatch , tmp_path ):
200269 iris .runtime .reset ()
201270 install_dir = tmp_path / "iris"
202271 other_dir = tmp_path / "other-iris"
203272 (install_dir / "bin" ).mkdir (parents = True )
204273 (install_dir / "lib" / "python" ).mkdir (parents = True )
205274 (other_dir / "bin" ).mkdir (parents = True )
275+ _set_loader_path (monkeypatch , install_dir )
206276
207277 fake_module = types .SimpleNamespace (
208278 __file__ = str (other_dir / "bin" / "pythonint.so" ),
@@ -233,6 +303,7 @@ def test_connect_path_ignores_stale_pythonint_module(monkeypatch, tmp_path):
233303 (install_dir / "bin" ).mkdir (parents = True )
234304 (install_dir / "lib" / "python" ).mkdir (parents = True )
235305 (other_dir / "bin" ).mkdir (parents = True )
306+ _set_loader_path (monkeypatch , install_dir )
236307
237308 stale_module = types .SimpleNamespace (
238309 __file__ = str (other_dir / "bin" / "pythonint.so" ),
@@ -272,6 +343,7 @@ def test_connect_path_only_prioritizes_install_dir_during_pythonint_import(monke
272343 (install_dir / "bin" ).mkdir (parents = True )
273344 (install_dir / "lib" / "python" ).mkdir (parents = True )
274345 seen_import_path = []
346+ _set_loader_path (monkeypatch , install_dir )
275347
276348 fake_module = types .SimpleNamespace (
277349 __file__ = str (install_dir / "bin" / "pythonint.so" ),
@@ -308,6 +380,7 @@ def test_connect_path_warns_when_backend_has_no_connect(monkeypatch, tmp_path):
308380 install_dir = tmp_path / "iris"
309381 (install_dir / "bin" ).mkdir (parents = True )
310382 (install_dir / "lib" / "python" ).mkdir (parents = True )
383+ _set_loader_path (monkeypatch , install_dir )
311384
312385 fake_module = types .SimpleNamespace (
313386 __file__ = str (install_dir / "bin" / "pythonint.so" ),
0 commit comments