kubeflow / pipelines

Machine Learning Pipelines for Kubeflow
https://www.kubeflow.org/docs/components/pipelines/
Apache License 2.0
3.53k stars 1.59k forks source link

[sdk] [question] How can I write test code for the code that uses the sdk? #7215

Closed zamonia500 closed 4 months ago

zamonia500 commented 2 years ago

/kind question

Environment

I implemented a python code to get the list of updated pipeline versions after a certain time offset using kfp.Client . This code implemented in a way that uses the methods of kfp.Client.

And now I'm trying to test this code, but this code holds bunch of kfp_server_api & kfp.Client methods. It's very inconvenient to mock these SDK code to write test code. Is there anyone who has tested the code using kfp.Client? Please share some good ideas thanks!

zamonia500 commented 2 years ago

/remove-kind bug

chensun commented 2 years ago

@zamonia500 , can you provide some details on what are you trying to test for? Are you testing a pipeline end to end? or it's more like local unit test for a component's implementation code?

This code implemented in a way that uses the methods of kfp.Client.

And now I'm trying to test this code, but this code holds bunch of kfp_server_api & kfp.Client methods.

If you're not looking for pipeline e2e test, your code probably shouldn't be bundled with kfp.Client.

zamonia500 commented 2 years ago

@zamonia500 , can you provide some details on what are you trying to test for? Are you testing a pipeline end to end? or it's more like local unit test for a component's implementation code?

This code implemented in a way that uses the methods of kfp.Client. And now I'm trying to test this code, but this code holds bunch of kfp_server_api & kfp.Client methods.

If you're not looking for pipeline e2e test, your code probably shouldn't be bundled with kfp.Client.

@chensun , sorry for late reply :( It's unit test for a client code to get list of pipelines and execute some of it using kfp.Client code.

looks like this

pipeline_id = kfp_client.get_pipeline_id(pipeline_name)
pipeline_versions = kfp_client.list_pipeline_versions(
    pipeline_id,
    page_size=1,
    sort_by="created_at desc",
)
experiment = kfp_client.create_experiment("zamonia500-exp")
generated_run = kfp_client.run_pipeline(
    experiment_id=experiment.id,
    job_name="zamonia500-job",
    params=pipeline_params,  # retrieved from somewhere
    version_id=pipeline_version.id,
)
rimolive commented 4 months ago

KFPv2 has test cases for sample pipelines, you can take a look and reuse in your tests. I'm closing this issue, but feel free if you think you have unanswered questions

https://github.com/kubeflow/pipelines/blob/master/samples/v2/component_with_optional_inputs_test.py

/close

google-oss-prow[bot] commented 4 months ago

@rimolive: Closing this issue.

In response to [this](https://github.com/kubeflow/pipelines/issues/7215#issuecomment-1991050276): >KFPv2 has test cases for sample pipelines, you can take a look and reuse in your tests. I'm closing this issue, but feel free if you think you have unanswered questions > >https://github.com/kubeflow/pipelines/blob/master/samples/v2/component_with_optional_inputs_test.py > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.