Skip to content

Commit a042318

Browse files
committed
tweak eval_quoted_string helper function in test_quote_py_str to be compatible with both (old versions of) Python 2.7 & 3.x
1 parent c941493 commit a042318

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

test/framework/easyconfig.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,10 +2147,13 @@ def eval_quoted_string(quoted_val, val):
21472147
"""
21482148
globals = dict()
21492149
try:
2150-
exec('res = %s' % quoted_val, globals)
2150+
# this is needlessly complicated because we can't use 'exec' here without potentially running
2151+
# into a SyntaxError bug in old Python 2.7 versions (for example when running the tests in CentOS 7.9)
2152+
# cfr. https://stackoverflow.com/questions/4484872/why-doesnt-exec-work-in-a-function-with-a-subfunction
2153+
edict = {}; eval(compile('res = %s' % quoted_val, '<string>', 'exec'), globals, edict)
21512154
except Exception as e: # pylint: disable=broad-except
21522155
self.fail('Failed to evaluate %s (from %s): %s' % (quoted_val, val, e))
2153-
return globals['res']
2156+
return edict['res']
21542157

21552158
def assertEqual_unquoted(quoted_val, val):
21562159
"""Assert that evaluating the quoted_val yields the val"""

0 commit comments

Comments
 (0)