Skip to content

Conversation

@axel-grc
Copy link
Collaborator

@axel-grc axel-grc commented Nov 28, 2025

  • Add -W error to treat Python warnings as test failures
  • Redirect stderr to /tmp/stderr.log to capture C++ warnings from ITK modules
  • Check stderr log for "Warning" messages and fail the build if found

This ensures the CI catches both Python and C++ warnings like unknown parameter from SWIG.

Copy link
Collaborator

@SimonRit SimonRit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but can you document in the commit log the reason for adding all these options? Can you also add a commit introducing a warning to check that it works? I would remove the commit before merging.

@axel-grc axel-grc changed the title ENH: Enhance pytest command to capture warnings and fail if any are f… ENH: Fail Python tests on warnings during runtime Nov 28, 2025
@axel-grc
Copy link
Collaborator Author

I removed rtkPolynomialGainCorrectionImageFilter from WRAPPER_SUBMODULE_ORDER, this should return a warning and the test should fail.

pip install pytest matplotlib
pytest $GITHUB_WORKSPACE/test/*.py -vv -W "ignore:builtin type swig"
pytest $GITHUB_WORKSPACE/test/*.py -vv -s -W error -W "ignore:builtin type swig" 2> /tmp/stderr.log
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of -W "ignore:builtin type swig"?
I'd suggest to use mktemp in place of /tmp/stderr.log to avoid problems with, e.g., two process writing on the same file.

Copy link
Collaborator Author

@axel-grc axel-grc Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to ignore some known issues in SWIG (tracked in swig/swig#2881). The warnings appear because SWIG is not setting the module attribute on its builtin types.
This should be fixed when ITK use SWIG 4.4.

I changed /tmp/stderr.log for mktemp

@axel-grc axel-grc force-pushed the PythonTest branch 2 times, most recently from 5ffdd0d to 0471c2a Compare December 15, 2025 10:28
Copy link
Collaborator

@SimonRit SimonRit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does not seem to work as the tests pass and rtkPolynomialGainCorrectionImageFilter jhas been removed from WRAPPER_SUBMODULE_ORDER?

@axel-grc axel-grc force-pushed the PythonTest branch 5 times, most recently from d4a4e53 to be99727 Compare December 17, 2025 12:11
- Redirect stderr to mktemp to capture C++ warnings from ITK modules
- Check stderr log for "Warning" messages and fail the build if found

This ensures the CI catches C++ warnings like unknown parameter from SWIG.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants