Skip to content

Commit bf37180

Browse files
authored
[test] fix test_pip_with_env_vars for python 3.12 support (#46591) (#46605)
<!-- Thank you for your contribution! Please review https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> ## Checks - [ ] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [ ] I've run `scripts/format.sh` to lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference. For example, if I added a method in Tune, I've added it in `doc/source/tune/api/` under the corresponding `.rst` file. - [ ] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [ ] Unit tests - [ ] Release tests - [ ] This PR is not tested :( Signed-off-by: hongchaodeng <[email protected]>
1 parent f00246f commit bf37180

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

python/ray/tests/test_runtime_env_complicated.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,13 +1021,22 @@ def spawn_child(self, name, runtime_env):
10211021
reason="This test is only run on linux CI machines.",
10221022
)
10231023
def test_pip_with_env_vars(start_cluster, tmp_path):
1024-
1024+
"""
1025+
The file structure:
1026+
$tmp_path/
1027+
1028+
├── setup.py
1029+
├── dist/ # the tar.gz file will be generated here
1030+
└── test_package/
1031+
└── test.py
1032+
"""
10251033
with chdir(tmp_path):
10261034
TEST_ENV_NAME = "TEST_ENV_VARS"
10271035
TEST_ENV_VALUE = "TEST"
10281036
package_name = "test_package"
1029-
package_dir = os.path.join(tmp_path, package_name)
1030-
try_to_create_directory(package_dir)
1037+
package_version = "0.0.1"
1038+
package_dir = tmp_path
1039+
try_to_create_directory(os.path.join(package_dir, package_name))
10311040

10321041
setup_filename = os.path.join(package_dir, "setup.py")
10331042
setup_code = """import os
@@ -1038,28 +1047,37 @@ class InstallTestPackage(install):
10381047
# this function will be called when pip install this package
10391048
def run(self):
10401049
assert os.environ.get('{TEST_ENV_NAME}') == '{TEST_ENV_VALUE}'
1050+
super().run()
10411051
10421052
setup(
1043-
name='test_package',
1044-
version='0.0.1',
1053+
name='{package_name}',
1054+
version='{package_version}',
10451055
packages=find_packages(),
10461056
cmdclass=dict(install=InstallTestPackage),
10471057
license="MIT",
10481058
zip_safe=False,
10491059
)
10501060
""".format(
1051-
TEST_ENV_NAME=TEST_ENV_NAME, TEST_ENV_VALUE=TEST_ENV_VALUE
1061+
TEST_ENV_NAME=TEST_ENV_NAME,
1062+
TEST_ENV_VALUE=TEST_ENV_VALUE,
1063+
package_name=package_name,
1064+
package_version=package_version,
10521065
)
1053-
with open(setup_filename, "wt") as f:
1066+
1067+
with open(setup_filename, "w+") as f:
10541068
f.writelines(setup_code)
10551069

1056-
python_filename = os.path.join(package_dir, "test.py")
1070+
python_filename = os.path.join(package_dir, package_name, "test.py")
10571071
python_code = "import os; print(os.environ)"
1058-
with open(python_filename, "wt") as f:
1072+
with open(python_filename, "w+") as f:
10591073
f.writelines(python_code)
10601074

1061-
gz_filename = os.path.join(tmp_path, package_name + ".tar.gz")
1062-
subprocess.check_call(["tar", "-zcvf", gz_filename, package_name])
1075+
gz_filename = os.path.join(
1076+
tmp_path,
1077+
"dist",
1078+
"{name}-{ver}.tar.gz".format(name=package_name, ver=package_version),
1079+
)
1080+
subprocess.check_call(["python", "setup.py", "sdist"])
10631081

10641082
with pytest.raises(ray.exceptions.RuntimeEnvSetupError):
10651083

0 commit comments

Comments
 (0)