Improve Python scripts
This MR contains various improvements for the Python-based CI test infrastructure. Some commits fix common Python issues (e.g., file handling), others improve the logging. The changes were quite useful in debugging some BASOP-related failures.