I am using cocotb version 1.5.2, and I would like to write an utility function to create reports/plots per test.
MWE: Implementing the get_test_name
function so that the following test will print my_wonderful_test
.
import cocotb
@cocotb.test()
async def my_wonderful_test(dut):
print(get_test_name(dut));
def get_test_name(dut):
pass # how do I get the current test from here?
Thank you for the commenters, and thank you @FabienM for trying to give an answer. Thank you for @Tzane for trying to find an answer. You were close.
If you want to know a one liner answer
but the underline prefix in
_test
maybe it will break in the future, but for since I was only concerned about version1.5.2
this is OK for me.Any way I implemented another method that scans the stack one level at a time and check if the frame is in a cocotb.test decorated function. This is also the method that cocotb uses to _discover_tests
It won't work if the test is in a closure, but I never use that, and I don't know if it is even supported.
I don't know why my questions are so badly received
It was something simple that I preferred to engage more people