@@ -237,6 +237,48 @@ def test_run_entrypoint_with_dependencies():
237237 sys .path .remove (module_dir )
238238
239239
240+ def test_add_py_folder_enables_local_imports ():
241+ """Test that add_py_folder adds entrypoint directory to sys.path for local imports."""
242+ from datacustomcode .run import add_py_folder
243+
244+ # Create a temporary directory structure
245+ temp_dir = tempfile .mkdtemp ()
246+
247+ try :
248+ # Create a utility module in the temp directory
249+ utility_path = os .path .join (temp_dir , "utility.py" )
250+ with open (utility_path , "w" ) as f :
251+ f .write ("TEST_VALUE = 'local_module_works'\n " )
252+
253+ # Create an entrypoint file
254+ entrypoint_path = os .path .join (temp_dir , "entrypoint.py" )
255+ with open (entrypoint_path , "w" ) as f :
256+ f .write ("# Test entrypoint\n " )
257+
258+ # Save original sys.path
259+ original_path = sys .path .copy ()
260+
261+ # Call add_py_folder with relative path from current directory
262+ relative_entrypoint = os .path .relpath (entrypoint_path )
263+ add_py_folder (relative_entrypoint )
264+
265+ # verify we can now import the utility module
266+ import utility
267+
268+ assert hasattr (utility , "TEST_VALUE" ), "utility module should have TEST_VALUE"
269+ assert (
270+ utility .TEST_VALUE == "local_module_works"
271+ ), f"Expected 'local_module_works', got { utility .TEST_VALUE } "
272+
273+ finally :
274+ # Cleanup
275+ sys .path = original_path
276+ if "utility" in sys .modules :
277+ del sys .modules ["utility" ]
278+ if os .path .exists (temp_dir ):
279+ shutil .rmtree (temp_dir )
280+
281+
240282class TestDataspaceScenarios :
241283 """Test dataspace functionality in run_entrypoint."""
242284
0 commit comments