pythoncocotb

How to print the content of TestError raised in Cocotb


If I raise a TestError under cocotb test coroutine :

@cocotb.test()
def double_cmd(dut):
    ...
    raise TestError("Wrong CRC value found")

I know that error raised in test log, but I don't see the message "Wrong CRC value found":

12580176.01ns ERROR    Test Failed: double_cmd (result was TestError)
12580176.01ns ERROR    Failed 1 out of 1 tests (3 skipped)
12580176.01ns INFO     ************************************************************************************
                       ** TEST                        PASS/FAIL  SIM TIME(NS)  REAL TIME(S)  RATIO(NS/S) **
                       ************************************************************************************
                       ** test_laser_com.simple_test     N/A            0.00          0.00         0.00  **
                       ** test_laser_com.wrong_crc       N/A            0.00          0.00         0.00  **
                       ** test_laser_com.gas_cmd         N/A            0.00          0.00         0.00  **
                       ** test_laser_com.double_cmd     FAIL     12580176.01         14.41    872921.37  **
                       ************************************************************************************

Is there a proper way to print the TestError message in log ?


Solution

  • The only solution I found currently is to print the message before raising TestError:

    @cocotb.test()
    def double_cmd(dut):
        ...
        dut._log.error("Wrong CRC value found")
        raise TestError()
    

    But maybe it's the thing to do?