Search code examples
pythonpytestopenpyxl

Openpyxl pytest - can't check the blank line


I have an empty string check. But the test does not pass successfully. I have tested with other cell values (like 5). The error wrote that I expect None and 5 is returned. But if I check the None condition and the cell is indeed empty, the error response writes that nothing at all was returned. How do I check that the cell is empty?

assert cell_values["marks"] is None, (f "The value in 'marks' is not None for row {row_number}. "
                                                          f "Actual: {cell_values['marks']}")

Solution

  • Your cell may be just an empty string, not a None. What I suggest is to check the correct value and type of what you thought was a None and change your condition accordingly.

    Here is what you can do if the value is None or an empty string.

    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}'"