【问题标题】:Handling single quotes in pytest parameter string处理 pytest 参数字符串中的单引号
【发布时间】:2020-09-18 05:21:05
【问题描述】:

在字符串值中有一个带有单引号的 pytest 参数。例如,

@pytest.mark.parametrize(
    'message1, code, message2', [
    ('test_exception_message', 'error_code_example', ''apples' are in the 'basket'')])

message2 = 'apples' are in the 'basket'

如何处理引号?谢谢。

【问题讨论】:

  • 参数使用双引号即可,例如"'apples' are in the 'basket'"。或者你可以逃脱他们:'\'apples\' are in the \'basket\''.
  • 它有效。谢谢。

标签: python pytest


【解决方案1】:
message2 = "'apples' are in the 'basket'"

使用双引号或转义使用

'\'apples\' are in the \'basket\''

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多