Skip to content

Commit

Permalink
[core] refactor worker sys path test (#45705)
Browse files Browse the repository at this point in the history
prints out `sys_path` got from remote, and reuse the package directory.

also, uses `sys.executable` instead of `python` from `PATH`, as in bazel
managed sandbox environments, these can be two different python
binaries.

Signed-off-by: Lonnie Liu <[email protected]>
  • Loading branch information
aslonnie authored Jun 4, 2024
1 parent cd1fc84 commit bec91a5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions python/ray/tests/test_basic_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def pid(self):
def test_worker_sys_path_contains_driver_script_directory(tmp_path, monkeypatch):
package_folder = tmp_path / "package"
package_folder.mkdir()
init_file = tmp_path / "package" / "__init__.py"
init_file = package_folder / "__init__.py"
init_file.write_text("")

module1_file = tmp_path / "package" / "module1.py"
module1_file = package_folder / "module1.py"
module1_file.write_text(
f"""
import sys
Expand All @@ -163,14 +163,15 @@ def test_worker_sys_path_contains_driver_script_directory(tmp_path, monkeypatch)
def sys_path():
return sys.path
assert r'{str(tmp_path / "package")}' in ray.get(sys_path.remote())
remote_sys_path = ray.get(sys_path.remote())
assert r'{str(package_folder)}' in remote_sys_path, remote_sys_path
"""
)
subprocess.check_call(["python", str(module1_file)])
subprocess.check_call([sys.executable, str(module1_file)])

# If the driver script is run via `python -m`,
# the script directory is not included in sys.path.
module2_file = tmp_path / "package" / "module2.py"
module2_file = package_folder / "module2.py"
module2_file.write_text(
f"""
import sys
Expand All @@ -181,11 +182,12 @@ def sys_path():
def sys_path():
return sys.path
assert r'{str(tmp_path / "package")}' not in ray.get(sys_path.remote())
remote_sys_path = ray.get(sys_path.remote())
assert r'{str(package_folder)}' not in remote_sys_path, remote_sys_path
"""
)
monkeypatch.chdir(str(tmp_path))
subprocess.check_call(["python", "-m", "package.module2"])
subprocess.check_call([sys.executable, "-m", "package.module2"])


def test_worker_kv_calls(monkeypatch, shutdown_only):
Expand Down

0 comments on commit bec91a5

Please sign in to comment.