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\HTMLTestRunner.py", line 620, in addError
100: suite ( run ) File "C:\Sikuli\sikulix.jar\Lib\unittest\suite.py", 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):

    @classmethod
    def setUpClass(cls):#(self):
        App.open(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
        wait(2)
        type(Key.F6)
        wait(1)
        paste(www.google.com)

        Debug.info("setUpClass called")

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

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

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

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

    def test_step_02(self):
        Debug.info("executing test step 2")
        type(Key.F6)
        paste(www.sikulix.com)
        type(Key.ENTER)
        wait(3)
        assert exists("SikuliX.png")

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

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

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-03-03
Last query:
2017-03-03
Last reply:
2017-03-03
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 runner.run(suite).

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.