ensure the main process raise an exception when the subprocess fails (#18663)

This commit is contained in:
Haifeng Jin 2023-10-21 02:52:38 -07:00 committed by GitHub
parent e3c68cd1d4
commit 353aaff034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,14 +20,13 @@ def setup_package():
shell=True,
)
print(build_process.stdout)
match = re.search(
r"\s[^\s]*\.whl",
whl_path = re.findall(
r"[^\s]*\.whl",
build_process.stdout,
)
if not match:
raise ValueError("Installing Keras package unsuccessful. ")
)[-1]
if not whl_path:
print(build_process.stderr)
whl_path = match.group()
raise ValueError("Installing Keras package unsuccessful. ")
return whl_path
@ -82,18 +81,21 @@ def cleanup():
def run_commands_local(commands):
for command in commands:
print(f"Running command: {command}")
subprocess.run(command, shell=True)
def run_commands_venv(commands):
for command in commands:
print(f"Running command: {command}")
cmd_with_args = command.split(" ")
cmd_with_args[0] = "test_env/bin/" + cmd_with_args[0]
p = subprocess.Popen(cmd_with_args)
p.wait()
assert p.wait() == 0
def test_keras_imports():
try:
# Ensures packages from all backends are installed.
# Builds Keras core package and returns package file path.
whl_path = setup_package()
@ -110,6 +112,7 @@ def test_keras_imports():
run_keras_flow()
# Removes virtual environment and associated files
finally:
cleanup()