Openpyxl pytest - 无法检查空行

问题描述 投票:0回答:1

我有一个空字符串检查。但测试没有成功通过。我已经用其他单元格值(例如 5)进行了测试。错误写道我期望 None 并且返回 5。 但是,如果我检查“无”条件并且单元格确实为空,则错误响应会写入根本没有返回任何内容。如何检查单元格是否为空?

assert cell_values["marks"] is None, (f "The value in 'marks' is not None for row {row_number}. "
                                                          f "Actual: {cell_values['marks']}")
python pytest openpyxl
1个回答
0
投票

您的单元格可能只是一个空字符串,而不是 None。我的建议是检查您认为 None 的正确值和类型,并相应地更改您的条件。

如果值为 None 或空字符串,您可以执行以下操作。

cell_value = cell_values["marks"]
assert cell_value is None or cell_value == "", \
    f"The value in 'marks' is not None or empty for row {row_number}. Actual: '{cell_value}'"
© www.soinside.com 2019 - 2024. All rights reserved.