From cb28a03dfc76d9063b4b4842f9fc93ad91e1b725 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Thu, 16 Jul 2026 08:18:35 +0200 Subject: [PATCH] [cppyy] Fix std::string return-type tests to match Pythonizations Un-xfail test18_operator_plus_overloads and test34_cstring_template_argument, which check that C++ functions returning a `std::string` produce a string on the Python side. These tests previously asserted the return type was exactly `cppyy.gbl.std.string`. That assumption is too strict: depending on which Pythonizations are enabled, a `std::string` returned from C++ may map to a different Python-side type. Compare instead against the type produced by a known `std::string`-returning function, `std::to_string(42)`, so the tests verify consistent behavior rather than one specific type. --- bindings/pyroot/cppyy/cppyy/test/test_regression.py | 6 ++++-- bindings/pyroot/cppyy/cppyy/test/test_templates.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bindings/pyroot/cppyy/cppyy/test/test_regression.py b/bindings/pyroot/cppyy/cppyy/test/test_regression.py index b006195a9cdd7..1838489408581 100644 --- a/bindings/pyroot/cppyy/cppyy/test/test_regression.py +++ b/bindings/pyroot/cppyy/cppyy/test/test_regression.py @@ -473,7 +473,6 @@ class Derived2 : public Base { assert a != b # derived class' C++ operator!= called - @mark.xfail(strict=True) def test18_operator_plus_overloads(self): """operator+(string, string) should return a string""" @@ -485,7 +484,10 @@ def test18_operator_plus_overloads(self): assert a == 'a' assert b == 'b' - assert type(a+b) == cppyy.gbl.std.string + # Expect same return type as other funcs returning a std::string in + # C++, which might be different from gbl.std.string on the Python side + # depending on the enabled Pythonizations. + assert type(a + b) == type(cppyy.gbl.std.to_string(42)) assert a+b == 'ab' def test19_std_string_hash(self): diff --git a/bindings/pyroot/cppyy/cppyy/test/test_templates.py b/bindings/pyroot/cppyy/cppyy/test/test_templates.py index 51ca569e1559e..d3116dafe7893 100644 --- a/bindings/pyroot/cppyy/cppyy/test/test_templates.py +++ b/bindings/pyroot/cppyy/cppyy/test/test_templates.py @@ -1142,7 +1142,6 @@ def test33_using_template_argument(self): assert ns.testptr assert cppyy.gbl.std.vector[ns.testptr] - @mark.xfail(strict=True) def test34_cstring_template_argument(self): """`const char*` use over std::string""" @@ -1160,7 +1159,10 @@ def test34_cstring_template_argument(self): ns = cppyy.gbl.CStringTemplateArg - assert type(ns.stringify("Alice")) == cppyy.gbl.std.string + # Expect same return type as other funcs returning a std::string in + # C++, which might be different from gbl.std.string on the Python side + # depending on the enabled Pythonizations. + assert type(ns.stringify("Alice")) == type(cppyy.gbl.std.to_string(42)) assert ns.stringify("Alice", "Bob") == "Alice Bob " assert ns.stringify(1, 2, 3) == "1 2 3 " assert ns.stringify["const char*"]("Aap") == "Aap "