Skip to content

[core] Deflake test_runtime_env_pip_and_conda_4.py #52750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 24 additions & 49 deletions python/ray/tests/test_runtime_env_conda_and_pip_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,59 +76,34 @@ def f3():
assert all(ray.get([f.remote(), f2.remote(), f3.remote()]))


class TestGC:
@pytest.mark.skipif(
os.environ.get("CI") and sys.platform != "linux",
reason="Requires PR wheels built in CI, so only run on linux CI machines.",
)
@pytest.mark.parametrize("field", ["pip"])
def test_pip_ray_is_overwritten(self, start_cluster, field):
cluster, address = start_cluster

# It should be OK to install packages with ray dependency.
ray.init(address, runtime_env={"pip": ["pip-install-test==0.5", "ray"]})

@ray.remote
def f():
import pip_install_test # noqa: F401

return True

# Ensure that the runtime env has been installed.
assert ray.get(f.remote())

ray.shutdown()

# It should be OK if cluster ray meets the installing ray version.
ray.init(address, runtime_env={"pip": ["pip-install-test==0.5", "ray>=1.12.0"]})

@ray.remote
def f():
import pip_install_test # noqa: F401

return True

# Ensure that the runtime env has been installed.
assert ray.get(f.remote())

ray.shutdown()

# It will raise exceptions if ray is overwritten.
with pytest.raises(Exception):
ray.init(
address, runtime_env={"pip": ["pip-install-test==0.5", "ray<=1.6.0"]}
)
@pytest.mark.skipif(
os.environ.get("CI") and sys.platform != "linux",
reason="Requires PR wheels built in CI, so only run on linux CI machines.",
)
@pytest.mark.parametrize("field", ["pip"])
def test_pip_ray_is_overwritten(start_cluster, field):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange diff rendering because I took this out of the TestGC nesting

cluster, address = start_cluster
ray.init(address)

@ray.remote
def f():
import pip_install_test # noqa: F401
@ray.remote
def f():
import pip_install_test # noqa: F401

return True
# Test an unconstrained "ray" dependency (should work).
ray.get(f.options(runtime_env={"pip": ["pip-install-test==0.5", "ray"]}).remote())

# Ensure that the runtime env has been installed.
assert ray.get(f.remote())
# Test a constrained "ray" dependency that matches the env (should work).
ray.get(
f.options(runtime_env={"pip": ["pip-install-test==0.5", "ray>=2.0"]}).remote()
)

ray.shutdown()
# Test a constrained "ray" dependency that doesn't match the env (shouldn't work).
with pytest.raises(Exception):
ray.get(
f.options(
runtime_env={"pip": ["pip-install-test==0.5", "ray<2.0"]}
).remote()
)


# pytest-virtualenv doesn't support Python 3.12 as of now, see more details here:
Expand Down