Taking Screenshot at the end of each test - Unittest - Get test case name in tear down method

Asked by Bunnings

Due to the OCR issues, I have decided to take a screenshot of the application after each test. I have to save the screenshot like testcasename.png . Is there any way I can get the name of the test case from the tear down method?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

--1. you might have a look at the modified HTMLTestRunner, that automatically takes shots for failing tests
https://answers.launchpad.net/sikuli/+question/176005

--2. there is no built in feature to get what you want
this might be a solution
- make a class variable currentID in the test class
- in each test def say at start:
<name of testclass>.currentID = id()
- then in teardown make your shot and name it using the info in <name of testclass>.currentID

look: http://docs.python.org/2/library/unittest.html#unittest.TestCase.id

Revision history for this message
Bunnings (sillybilly) said :
#2

Thanks RaiMan, that solved my question.