Unittest - unable to start the application from setup

Asked by etherman

**** setup function in class TestCase is named

setUp() # uppercase u

-------------------------------------------------

In unittest unable to start the application from setup but same code works in tes1. Not sure what i am doing wrong. Here is the code snippet

dir = "c:/SikuliScripts/HTMLTestRunner"
import os
fp = file(os.path.join(dir, "AViewTest.html"), "wb")

import unittest
import HTMLTestRunner
reload(HTMLTestRunner)

class MyTest1(unittest.TestCase):
    def setup(self):
        #aview = App(r'C:/Files/Classroom/Classroom.exe') # not able to start the app
        #aview.open()
        wait(5)
    def test1(self):
        aview = App(r'C:/Files/Classroom/Classroom.exe') # same scripts I can run from here
        aview.open()
class MyTest2(unittest.TestCase):
    def test1(self):
        assert False

suite = unittest.TestLoader().loadTestsFromTestCase(MyTest1)
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(MyTest2))
runner = HTMLTestRunner.HTMLTestRunner(stream = fp, verbosity=2, dirTestScreenshots = dir)
runner.run(suite)
fp.close()

Question information

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

not really clear, what your problem is.
please talk about, what you want to achieve and paste error messages if any.

setUp() is specific for each class TestCase().

each class TestCase can have as many testXXX() as you like.
per class TestCase, each testXXX is preceded by the class's setUp() and followed by the class's teardown.

So usually tests are grouped in one class, according to the fact, that they need the same setUp() and tearDown().

--- aview = App(r'C:/Files/Classroom/Classroom.exe') # not able to start the app
when using raw strings, you have to use \

Revision history for this message
etherman (nambiar) said :
#2

Hi RaiMan,
i want to start the application from the setup and execute bunch of
testcases in other functions. but I cannot start the application from setup
even after change to \. Here is the code snippet I used

class MyTest1(unittest.TestCase):
    def setup(self):
        aview = App(r'C:\Program Files\A-VIEW Classroom\A-VIEW
Classroom.exe')
        aview.open()
    def test1(self):
        pass

Just to make sure it is not due to the syntax error I tried the exact code
by copy/paste from setup to test1 function and the application was
started.

Thanks

On Wed, Apr 4, 2012 at 2:30 PM, RaiMan <<email address hidden>
> wrote:

> Your question #192601 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/192601
>
> Status: Open => Needs information
>
> RaiMan requested more information:
> not really clear, what your problem is.
> please talk about, what you want to achieve and paste error messages if
> any.
>
> setUp() is specific for each class TestCase().
>
> each class TestCase can have as many testXXX() as you like.
> per class TestCase, each testXXX is preceded by the class's setUp() and
> followed by the class's teardown.
>
> So usually tests are grouped in one class, according to the fact, that
> they need the same setUp() and tearDown().
>
> --- aview = App(r'C:/Files/Classroom/Classroom.exe') # not able to start
> the app
> when using raw strings, you have to use \
>
> --
> To answer this request for more information, you can either reply to
> this email or enter your reply at the following page:
> https://answers.launchpad.net/sikuli/+question/192601
>
> You received this question notification because you asked the question.
>

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Aaaaaarrrrgh ***

Did not see it:

the function is named:

setUp()

sorry, for being blind ;-)

Revision history for this message
etherman (nambiar) said :
#4

Hi RaiMan,

That is funny!
Sorry I should have been more careful.

Appreciate your help and being patient at my stupid mistake.

Regards,
/Prem

On Wed, Apr 4, 2012 at 5:50 PM, RaiMan <<email address hidden>
> wrote:

> Your question #192601 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/192601
>
> Description changed to:
> **** setup function in class TestCase is named
>
> setUp() # uppercase u
>
> -------------------------------------------------
>
> In unittest unable to start the application from setup but same code
> works in tes1. Not sure what i am doing wrong. Here is the code snippet
>
> dir = "c:/SikuliScripts/HTMLTestRunner"
> import os
> fp = file(os.path.join(dir, "AViewTest.html"), "wb")
>
> import unittest
> import HTMLTestRunner
> reload(HTMLTestRunner)
>
> class MyTest1(unittest.TestCase):
> def setup(self):
> #aview = App(r'C:/Files/Classroom/Classroom.exe') # not able to
> start the app
> #aview.open()
> wait(5)
> def test1(self):
> aview = App(r'C:/Files/Classroom/Classroom.exe') # same scripts I
> can run from here
> aview.open()
> class MyTest2(unittest.TestCase):
> def test1(self):
> assert False
>
> suite = unittest.TestLoader().loadTestsFromTestCase(MyTest1)
> suite.addTests(unittest.TestLoader().loadTestsFromTestCase(MyTest2))
> runner = HTMLTestRunner.HTMLTestRunner(stream = fp, verbosity=2,
> dirTestScreenshots = dir)
> runner.run(suite)
> fp.close()
>
> --
> You received this question notification because you asked the question.
>

Revision history for this message
RaiMan (raimund-hocke) said :
#5

typo