When running op-test with Python 3.12, a large number of SyntaxWarning appear due to unescaped backslashes in string literals that are used as regular expressions or command strings.
Python 3.12 introduces stricter handling of escape sequences in string literals. These warnings stem from sequences like \d, \[ or \( that are not within raw strings (i.e., they should be written as r"\d" instead of just "\d").
Example warnings:
/tmp/op-test-framework/common/OPexpect.py:74: SyntaxWarning: invalid escape sequence '\['
"\[[0-9. ]+,0\] Assert fail:",
/tmp/op-test-framework/common/OpTestIPMI.py:1395: SyntaxWarning: invalid escape sequence '\('
matchObj = re.search("BIOS Golden Side \((.*)\)", output)
/tmp/op-test-framework/common/OpTestUtil.py:2572: SyntaxWarning: invalid escape sequence '\w'
match = re.search('SESSION=(\w+);', cookie)
These warnings don’t break the functionality yet, but they could lead to issues in future Python versions or during stricter linting/static analysis.
Suggested Fix:
To resolve these warnings, convert affected string literals used in regex or shell commands to raw strings (prefix them with r), e.g.:
re.search(r"BIOS Golden Side \((.*)\)", output)
Below is the output of running op-test --help in python 3.12 showing all the SyntaxWarning messages.
op-test.250409.155330.status.txt
When running
op-testwith Python 3.12, a large number ofSyntaxWarningappear due to unescaped backslashes in string literals that are used as regular expressions or command strings.Python 3.12 introduces stricter handling of escape sequences in string literals. These warnings stem from sequences like
\d,\[or\(that are not within raw strings (i.e., they should be written asr"\d"instead of just"\d").Example warnings:
These warnings don’t break the functionality yet, but they could lead to issues in future Python versions or during stricter linting/static analysis.
Suggested Fix:
To resolve these warnings, convert affected string literals used in regex or shell commands to raw strings (prefix them with
r), e.g.:Below is the output of running
op-test --helpin python 3.12 showing all the SyntaxWarning messages.op-test.250409.155330.status.txt