Skip to content

Commit 1c11abc

Browse files
committed
Add test_standalone_enum_module.py, standalone_enum_module.cpp
1 parent 3b2d426 commit 1c11abc

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ set(PYBIND11_TEST_FILES
172172
test_scoped_critical_section
173173
test_sequences_and_iterators
174174
test_smart_ptr
175+
test_standalone_enum_module.py
175176
test_stl
176177
test_stl_binders
177178
test_tagbased_polymorphic
@@ -249,6 +250,7 @@ tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already
249250
tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils")
250251
tests_extra_targets("test_cpp_conduit.py"
251252
"exo_planet_pybind11;exo_planet_c_api;home_planet_very_lonely_traveler")
253+
tests_extra_targets("test_standalone_enum_module.py" "standalone_enum_module")
252254

253255
set(PYBIND11_EIGEN_REPO
254256
"https://gitlab.com/libeigen/eigen.git"

tests/standalone_enum_module.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2026 The pybind Community.
2+
3+
#include <pybind11/pybind11.h>
4+
5+
namespace standalone_enum_module_ns {
6+
enum class SomeEnum { value1, value2 };
7+
}
8+
9+
using namespace standalone_enum_module_ns;
10+
11+
PYBIND11_MODULE(standalone_enum_module, m) {
12+
pybind11::enum_<SomeEnum>(m, "SomeEnum")
13+
.value("value1", SomeEnum::value1)
14+
.value("value2", SomeEnum::value2);
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import annotations
2+
3+
import os
4+
5+
import env
6+
7+
8+
def test_enum_import_exit_no_crash():
9+
# Modeled after reproducer under issue #5976
10+
env.check_script_success_in_subprocess(
11+
f"""
12+
import sys
13+
sys.path.insert(0, {os.path.dirname(env.__file__)!r})
14+
import standalone_enum_module as m
15+
assert int(m.SomeEnum.value1) == 0
16+
assert int(m.SomeEnum.value2) == 1
17+
""",
18+
rerun=1,
19+
)

0 commit comments

Comments
 (0)