Skip to content

Commit

Permalink
Fixing failing SDK test by replacing mock.patch with subprocess for a…
Browse files Browse the repository at this point in the history
…ctual build

The original test used mock.patch to mock subprocess.run, which prevented the real KFP package build from occurring. This caused the test to fail as it couldn't find the expected artifacts.
Replaced the mock with a direct subprocess.run call to ensure the package is built correctly during the test. This resolves the issue by performing the actual build process, making the test more reliable and surfacing any build errors clearly.

Signed-off-by: ddalvi <[email protected]>
  • Loading branch information
DharmitD committed Oct 14, 2024
1 parent 753a2f1 commit d887106
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions sdk/python/kfp/cli/component_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
"""Tests for `components` command group in KFP CLI."""
import contextlib
import functools
import os
import pathlib
import subprocess
Expand Down Expand Up @@ -579,27 +578,28 @@ def test_existing_dockerfile_can_be_overwritten(self):
COPY . .
'''))

@unittest.skip(
"Skipping this test as it's failing. Refer to https://github.com/kubeflow/pipelines/issues/11038"
)
def test_dockerfile_can_contain_custom_kfp_package(self):
component = _make_component(
func_name='train', target_image='custom-image')
_write_components('components.py', component)
package_dir = os.path.dirname(os.path.dirname(self.current_dir))

# suppresses large stdout from subprocess that builds kfp package
with mock.patch.object(
subprocess,
'run',
new=functools.partial(subprocess.run, capture_output=True)):
result = self.runner.invoke(
self.cli,
[
'build',
str(self._working_dir), f'--kfp-package-path={package_dir}'
],
)
try:
subprocess.run(['python3', 'setup.py', 'bdist_wheel'],
cwd=package_dir,
check=True,
capture_output=True)
except subprocess.CalledProcessError as e:
print(f'Failed to build KFP package: {e.stderr.decode()}')
raise

result = self.runner.invoke(
self.cli,
[
'build',
str(self._working_dir), f'--kfp-package-path={package_dir}'
],
)
self.assertEqual(result.exit_code, 0)
self._docker_client.api.build.assert_called_once()
self.assert_file_exists('Dockerfile')
Expand Down

0 comments on commit d887106

Please sign in to comment.