Run python test by the CI

Hello, I’m working on the CudaCommon remote module and need an efficient way to test Python packages from generated wheels in our CI pipeline. Current options have limitations:

The first approach with itk_python_add_test

  • Add Python tests using itk_python_add_test in the module’s CMakeLists.txt
  • These tests run via CTest with a specific label: ctest -L Python.
  • Key issue: This requires building ITK with Python wrapping enabled (-DITK_WRAP_PYTHON=ON), which is time-consuming.

Alternative approaches I’m considering:

  1. Use pytest directly as done in ITKRemoteModuleBuildTestPackageAction for notebooks, but this disconnects the tests from CTest.
  2. Add a python-test flag in CudaCommon , which simplify the configuration (I just have to configure CudaCommon with the flag enabled, see my PR), but I would like to avoid creating new flags.

Has anyone developed an efficient workflow for testing Python-wrapped modules without rebuilding ITK each time? What approach do you recommend?

Hi @axel_garcia ,

When we build the itk python packages, we finish by:

  • Testing installation of the built wheels
  • Running a few tests with the contents of those wheels.

For example, on Linux:

The ITKPythonPackage remote module build scripts could be extended to:

  1. Install the built packages
  2. Install pytest
  3. Run pytest and have it discover any tests following pytest’s naming conventions.
1 Like

Thanks for your quick answer. If I understand correctly, ITK uses Python tests declared with itk_python_add_test, run by the CI e.g. in AzurePipelinesLinuxPython.yml but you would not recommend using this for testing the Python code of remote modules but to prefer instead using pytest?

We have two types of functionality to test:

  1. Are the wrappers we generate during development working correctly?
  2. Are the packages we generate working correctly from an installation?

For the former, yes, itk_python_add_test makes CI and development possible. For the latter, testing after installation is desirable. It should be possible to use the same testing for both itk_python_add_test and pytest by naming the test files test_*.