Skip to content

Commit 4fa88e6

Browse files
committed
Add PYBIND11_CATCH2_SKIP_IF macro to skip tests at runtime
Catch2 v2 doesn't have native skip support (v3 does with SKIP()). This macro allows tests to be skipped with a visible message while still appearing in the test list. Use this for the Move Subinterpreter test on free-threaded Python 3.14+ so it shows as skipped rather than being conditionally compiled out. Example output: [ RUN ] Move Subinterpreter [ SKIPPED ] Skipped on free-threaded Python 3.14+ (see PR pybind#5940) [ OK ] Move Subinterpreter
1 parent 4aa1e0d commit 4fa88e6

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

tests/test_with_catch/catch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PYBIND11_WARNING_DISABLE_MSVC(4996)
2525

2626
#define CATCH_CONFIG_RUNNER
2727
#define CATCH_CONFIG_DEFAULT_REPORTER "progress"
28+
#include "catch_skip.h"
29+
2830
#include <catch.hpp>
2931

3032
namespace py = pybind11;

tests/test_with_catch/catch_skip.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Macro to skip a test at runtime with a visible message.
2+
// Catch2 v2 doesn't have native skip support (v3 does with SKIP()).
3+
// The test will count as "passed" in totals, but the output clearly shows it was skipped.
4+
5+
#pragma once
6+
7+
#include <catch.hpp>
8+
9+
#define PYBIND11_CATCH2_SKIP_IF(condition, reason) \
10+
do { \
11+
if (condition) { \
12+
Catch::cout() << "[ SKIPPED ] " << reason << '\n'; \
13+
Catch::cout().flush(); \
14+
return; \
15+
} \
16+
} while (0)

tests/test_with_catch/test_subinterpreter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// catch 2.0.1; this should be fixed in the next catch release after 2.0.1).
77
PYBIND11_WARNING_DISABLE_MSVC(4996)
88

9+
# include "catch_skip.h"
10+
911
# include <catch.hpp>
1012
# include <cstdlib>
1113
# include <fstream>
@@ -90,11 +92,15 @@ TEST_CASE("Single Subinterpreter") {
9092
unsafe_reset_internals_for_single_interpreter();
9193
}
9294

93-
// "Move Subinterpreter" test is disabled on free-threaded Python 3.14+ due to a hang
94-
// in Py_EndInterpreter() when the subinterpreter is destroyed from a different thread
95-
// than it was created on. See: https://github.com/pybind/pybind11/pull/5940
96-
# if PY_VERSION_HEX >= 0x030D0000 && !(PY_VERSION_HEX >= 0x030E0000 && defined(Py_GIL_DISABLED))
95+
# if PY_VERSION_HEX >= 0x030D0000
9796
TEST_CASE("Move Subinterpreter") {
97+
// Test is skipped on free-threaded Python 3.14+ due to a hang in Py_EndInterpreter()
98+
// when the subinterpreter is destroyed from a different thread than it was created on.
99+
// See: https://github.com/pybind/pybind11/pull/5940
100+
# if PY_VERSION_HEX >= 0x030E0000 && defined(Py_GIL_DISABLED)
101+
PYBIND11_CATCH2_SKIP_IF(true, "Skipped on free-threaded Python 3.14+ (see PR #5940)");
102+
# endif
103+
98104
std::unique_ptr<py::subinterpreter> sub(new py::subinterpreter(py::subinterpreter::create()));
99105

100106
// on this thread, use the subinterpreter and import some non-trivial junk

0 commit comments

Comments
 (0)