Disable stdout buffering in test_with_catch

Ensure test output appears immediately in CI logs by disabling stdout
buffering. Without this, output may be lost if the process is killed
by a timeout, making it difficult to diagnose which test was hanging.
This commit is contained in:
Ralf W. Grosse-Kunstleve
2025-12-20 19:37:53 -08:00
parent cb5e7d751a
commit 0f8f32a92a

View File

@@ -4,6 +4,7 @@
#include <pybind11/embed.h>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iomanip>
#include <sstream>
@@ -103,6 +104,11 @@ std::string get_utc_timestamp() {
} // namespace
int main(int argc, char *argv[]) {
// Disable stdout buffering to ensure output appears immediately in CI logs.
// Without this, output may be lost if the process is killed by a timeout.
std::cout.setf(std::ios::unitbuf);
setvbuf(stdout, nullptr, _IONBF, 0);
// Setup for TEST_CASE in test_interpreter.cpp, tagging on a large random number:
std::string updated_pythonpath("pybind11_test_with_catch_PYTHONPATH_2099743835476552");
const char *preexisting_pythonpath = getenv("PYTHONPATH");