setUpClass does not run with HTMLTestrunner

Asked by Dale Botman on 2017-03-03

Attempted to run a test scenario/Testcase using the setUpClass(cls) and tearDownClass python unittest methods.

Note: The same script works using setUp(self) and tearDown(self) method. However the setup/teardown is called at every test_ def.

When running with the setUpClass(cls) and tearDownClass the following error is produced, from what I believe is an error in the HTMLTestrunner.

"[error] AttributeError ( '_TestResult' object has no attribute 'outputBuffer' )
[error] --- Traceback --- error source first
line: module ( function ) statement
594: HTMLTestRunner ( complete_output ) AttributeError: '_TestResult' object h
s no attribute 'outputBuffer'
198: suite ( _addClassOrModuleLevelException ) File "C:\Sikuli\sikulix.jar\L
b\", line 620, in addError
100: suite ( run ) File "C:\Sikuli\sikulix.jar\Lib\unittest\", line
53, in _handleClassSetUp
678: HTMLTestRunner ( run ) File "C:\Sikuli\sikulix.jar\Lib\unittest\suite.p
", line 70, in __call__
[error] --- Traceback --- end --------------

Stuck at how to get the outputbuffer attribute triggered. I think I need to edit the complete_output and the addError def in the HTMLTestrunner however I am not sure what to edit.

Here is an example of the script I am attempting to run.

from sikuli import *
import os
import sys
import HTMLTestRunner
import time
import unittest
#import utils
import org.sikuli.basics.SikulixForJython

dir = "C:\Sikuli\Test\Test"
if not dir in sys.path: sys.path.append(dir)
fp = file(os.path.join(dir, "SetupClass_TestReport.html"), "wb")

class TestcaseSetupScenario(unittest.TestCase):

    def setUpClass(cls):#(self):'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
        paste("setUpClass called")

    #def setUp(self):
        #print "testing 123"

    def tearDownClass(cls):#(self):
        App.close('Mozilla Firefox')"tearDownClass called")

    #def tearDown(self):
        #print "321 testing"

    def test_step_01(self):"executing test step 1")
        assert exists("google_search.png")

    def test_step_02(self):"executing test step 2")
        assert exists("SikuliX.png")

    def test_step_03_(self):"executing test step 3")
        assert exists("Sikuli.png")

suite = unittest.TestLoader().loadTestsFromTestCase(TestcaseSetupScenario)
runner = HTMLTestRunner.HTMLTestRunner(stream = fp, verbosity=1, dirTestScreenshots = dir)

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Best RaiMan (raimund-hocke) said : #1

As far as I remember HTMLTestRunner (years ago, when I implemented the SikuliX feature ;-), it does not know anything about setUpClass.

So I recommend, to not dig around in HTMLTestRunner, but move the setUpClass code to the outside in the script before and after the

Dale Botman (mandalus) said : #2

Aha! that's a pragmatic approach to the problem! thanks for the suggestion!

Thanks for all other information you've added I've managed to come pretty far with your information!

Thanks Raiman!

Dale Botman (mandalus) said : #3

Thanks RaiMan, that solved my question.

Dale Botman (mandalus) said : #4

Thanks again Raiman, that practical approach solved my issue hopefully with some experience I'd think of simple solutions like that quicker :-)

thanks for all your work its appreciated :-)

RaiMan (raimund-hocke) said : #5

Your welcome. Thanks for kind feedback.