Sikuli xmlrunner/htmlrunner with try catch in test cases

Asked by stewazy on 2017-04-07

Hello everyone, I want to aplogize to Raiman, I'm openning a new question related to xmlrunner/html runner.

First off I'm using this xml runner.I have a problem logging error in a file log.log and at the same time getting a correct xmlreport.xml report. When I have try to run my suite the logging works flawlessly but the xmlreport generates a positive report every time, regardless if my test fails.

Here is my test setup:

import unittest
import sys
import logging
import os
import traceback

from sikuli import *

class setUp(unittest.TestCase):
    def setUp(self):
        file = open("C:\\Sikuli\\log.log", 'a')
        file.write('Starting")
        file.close()

        wait(1)

    def tearDown(self):
        file = open("C:\\Sikuli\\log.log", 'a')
        file.write('Ending")
        file.close()

    def myTest(self):
        try:
            #test
        except:
            var = traceback.format_exc()
            file = open("C:\\Sikuli\\log.log", 'a')
            file.write(var)
            file.close()

Here is my runner setup

import sys
import os

if not helpersPath in sys.path: sys.path.append(helpersPath)
MyTestPath = "C:\\Sikuli\\Mytests"
if not MyTestPath in sys.path: sys.path.append(MyTestPath )

from xmlrunner import *
from sikuli.Sikuli import *
from MyTest import *

#setup - clean log file
fileName = "C:\\Sikuli\\log.log"
f = open(fileName,'w')
f.truncate()
f.close()

suite=unittest.TestLoader().loadTestsFromTestCase(myTest)

result = XMLTestRunner(file("C:\\Sikuli\\test-results.xml", "w")).run(suite)

Is there any way that I can get the error in my log file and at the same time to generate a working xmlresult file at the end ? Thank you in advance and especially for your patience with me :) I a python newbie :)

Question information

Language:
English Edit question
Status:
Expired
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-04-07
Last reply:
2017-04-22
Launchpad Janitor (janitor) said : #1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.