← Back to team overview

sikuli-driver team mailing list archive

[Question #288480]: Using observe() for region created via default argument

 

New question #288480 on Sikuli:
https://answers.launchpad.net/sikuli/+question/288480

Hi,
I get some weird behavior when using observe() functionality for region defined via default argument
So I prepared code sample below

import unittest

def wait_load(observe_region=Region(399,25,1040,406)):
    observe_region.onChange(100, observe_region.stopObserver())
    observe_region.observe(20)

class SampleTest(unittest.TestCase):

    def test_one(self):
        wait(5)
        print('1st start')
        wait_load()
        assert True

    def test_two(self):
        wait(5)
        print('2nd start')
        wait_load()
        assert True

if __name__ == '__main__':
    runner = unittest.TextTestRunner(verbosity=2)
    SampleTestSuite = unittest.TestSuite(unittest.TestLoader().loadTestsFromTestCase(SampleTest))
    runner.run(SampleTestSuite)

So, after the launch i get:
>>test_one (__main__.SampleTest) ...
>>1st start
 
here i make two actions in observed region (for example move some window in and out)
After that second test also reported as successful at once, even if no actions was performed

I know that in Python "expressions in default arguments are calculated when the function is defined, not when it’s called", but here in default argument im just creating Region object. Ofcourse it is possible to call wait_load(Region(399,25,1040,406)) with argument, but in case of dozens of tests it is hard to manage them.

So how should I use observe() correctly in this case? 

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.