diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index af57b8c7d..be7232e5a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -535,6 +535,7 @@ endif() add_custom_target( memcheck COMMAND + PYBIND11_TESTING_WITH_VALGRIND=1 PYTHONMALLOC=malloc valgrind --leak-check=full diff --git a/tests/test_type_caster_odr_guard_1.py b/tests/test_type_caster_odr_guard_1.py index ac26f982c..1415501e8 100644 --- a/tests/test_type_caster_odr_guard_1.py +++ b/tests/test_type_caster_odr_guard_1.py @@ -1,3 +1,5 @@ +import os + import pytest import pybind11_tests.type_caster_odr_guard_1 as m @@ -35,5 +37,12 @@ def test_type_caster_odr_violation_detected_counter(): num_violations = m.type_caster_odr_violation_detected_count() if num_violations is None: pytest.skip("type_caster_odr_violation_detected_count() is None") + elif ( + os.environ.get("PYBIND11_TESTING_WITH_VALGRIND") is not None + and num_violations == 0 + ): + pytest.skip( + "UNEXPECTED: type_caster_odr_violation_detected_count() == 0 (valgrind)" + ) else: assert num_violations == 1