12
12
os .environ ["RAY_RUNTIME_ENV_LOCAL_DEV_MODE" ] = "1"
13
13
14
14
15
- def test_in_virtualenv (start_cluster ):
15
+ def test_in_virtualenv (ray_start_regular_shared ):
16
16
assert (
17
17
virtualenv_utils .is_in_virtualenv () is False
18
18
and "IN_VIRTUALENV" not in os .environ
19
19
) or (virtualenv_utils .is_in_virtualenv () is True and "IN_VIRTUALENV" in os .environ )
20
- cluster , address = start_cluster
21
- runtime_env = {"pip" : ["pip-install-test==0.5" ]}
22
20
23
- ray .init (address , runtime_env = runtime_env )
24
-
25
- @ray .remote
21
+ @ray .remote (runtime_env = {"pip" : ["pip-install-test==0.5" ]})
26
22
def f ():
27
23
import pip_install_test # noqa: F401
28
24
@@ -33,102 +29,58 @@ def f():
33
29
assert ray .get (f .remote ())
34
30
35
31
36
- def test_multiple_pip_installs (start_cluster , monkeypatch ):
32
+ @pytest .mark .skipif (
33
+ sys .platform == "win32" , reason = "python.exe in use during deletion."
34
+ )
35
+ def test_multiple_pip_installs (ray_start_regular_shared ):
37
36
"""Test that multiple pip installs don't interfere with each other."""
38
- monkeypatch .setenv ("RUNTIME_ENV_RETRY_TIMES" , "0" )
39
- cluster , address = start_cluster
40
-
41
- if sys .platform == "win32" and "ray" not in address :
42
- pytest .skip (
43
- "Failing on windows, as python.exe is in use during deletion attempt."
44
- )
45
-
46
- ray .init (
47
- address ,
48
- runtime_env = {
49
- "pip" : ["pip-install-test" ],
50
- "env_vars" : {"TEST_VAR_1" : "test_1" },
51
- },
52
- )
53
37
54
38
@ray .remote
55
39
def f ():
56
- return True
57
-
58
- @ray .remote (
59
- runtime_env = {
60
- "pip" : ["pip-install-test" ],
61
- "env_vars" : {"TEST_VAR_2" : "test_2" },
62
- }
63
- )
64
- def f2 ():
65
- return True
40
+ return os .environ ["TEST_VAR" ]
41
+
42
+ assert ray .get (
43
+ [
44
+ f .options (
45
+ runtime_env = {
46
+ "pip" : ["pip-install-test" ],
47
+ "env_vars" : {"TEST_VAR" : "1" },
48
+ }
49
+ ).remote (),
50
+ f .options (
51
+ runtime_env = {
52
+ "pip" : ["pip-install-test" ],
53
+ "env_vars" : {"TEST_VAR" : "2" },
54
+ }
55
+ ).remote (),
56
+ ]
57
+ ) == ["1" , "2" ]
66
58
67
- @ray .remote (
68
- runtime_env = {
69
- "pip" : ["pip-install-test" ],
70
- "env_vars" : {"TEST_VAR_3" : "test_3" },
71
- }
72
- )
73
- def f3 ():
74
- return True
75
59
76
- assert all (ray .get ([f .remote (), f2 .remote (), f3 .remote ()]))
60
+ @pytest .mark .skipif (
61
+ os .environ .get ("CI" ) and sys .platform != "linux" ,
62
+ reason = "Requires PR wheels built in CI, so only run on linux CI machines." ,
63
+ )
64
+ def test_pip_ray_is_overwritten (ray_start_regular_shared ):
65
+ @ray .remote
66
+ def f ():
67
+ import pip_install_test # noqa: F401
77
68
69
+ # Test an unconstrained "ray" dependency (should work).
70
+ ray .get (f .options (runtime_env = {"pip" : ["pip-install-test==0.5" , "ray" ]}).remote ())
78
71
79
- class TestGC :
80
- @pytest .mark .skipif (
81
- os .environ .get ("CI" ) and sys .platform != "linux" ,
82
- reason = "Requires PR wheels built in CI, so only run on linux CI machines." ,
72
+ # Test a constrained "ray" dependency that matches the env (should work).
73
+ ray .get (
74
+ f .options (runtime_env = {"pip" : ["pip-install-test==0.5" , "ray>=2.0" ]}).remote ()
83
75
)
84
- @pytest .mark .parametrize ("field" , ["pip" ])
85
- def test_pip_ray_is_overwritten (self , start_cluster , field ):
86
- cluster , address = start_cluster
87
-
88
- # It should be OK to install packages with ray dependency.
89
- ray .init (address , runtime_env = {"pip" : ["pip-install-test==0.5" , "ray" ]})
90
-
91
- @ray .remote
92
- def f ():
93
- import pip_install_test # noqa: F401
94
-
95
- return True
96
-
97
- # Ensure that the runtime env has been installed.
98
- assert ray .get (f .remote ())
99
-
100
- ray .shutdown ()
101
-
102
- # It should be OK if cluster ray meets the installing ray version.
103
- ray .init (address , runtime_env = {"pip" : ["pip-install-test==0.5" , "ray>=1.12.0" ]})
104
76
105
- @ray .remote
106
- def f ():
107
- import pip_install_test # noqa: F401
108
-
109
- return True
110
-
111
- # Ensure that the runtime env has been installed.
112
- assert ray .get (f .remote ())
113
-
114
- ray .shutdown ()
115
-
116
- # It will raise exceptions if ray is overwritten.
117
- with pytest .raises (Exception ):
118
- ray .init (
119
- address , runtime_env = {"pip" : ["pip-install-test==0.5" , "ray<=1.6.0" ]}
120
- )
121
-
122
- @ray .remote
123
- def f ():
124
- import pip_install_test # noqa: F401
125
-
126
- return True
127
-
128
- # Ensure that the runtime env has been installed.
129
- assert ray .get (f .remote ())
130
-
131
- ray .shutdown ()
77
+ # Test a constrained "ray" dependency that doesn't match the env (shouldn't work).
78
+ with pytest .raises (Exception ):
79
+ ray .get (
80
+ f .options (
81
+ runtime_env = {"pip" : ["pip-install-test==0.5" , "ray<2.0" ]}
82
+ ).remote ()
83
+ )
132
84
133
85
134
86
# pytest-virtualenv doesn't support Python 3.12 as of now, see more details here:
@@ -158,7 +110,7 @@ def test_run_in_virtualenv(cloned_virtualenv):
158
110
@pytest .mark .skipif (
159
111
"IN_VIRTUALENV" in os .environ , reason = "Pip option not supported in virtual env."
160
112
)
161
- def test_runtime_env_with_pip_config (start_cluster ):
113
+ def test_runtime_env_with_pip_config (ray_start_regular_shared ):
162
114
@ray .remote (
163
115
runtime_env = {
164
116
"pip" : {"packages" : ["pip-install-test==0.5" ], "pip_version" : "==24.1.2" }
0 commit comments