2

We develop extensions for Chrome, Firefox and Safari and we test our Chrome and Firefox extensions with Selenium. I recently added the timeout_decorator to stop the tests if they run more than 15 minutes (you can see the answers to my former question), and it works on Linux (Ubuntu). But the problem is, it doesn't work on Windows. Here is my code:

import timeout_decorator
....
class BaseSeleniumTestCase(unittest.TestCase):
....
    @timeout_decorator.timeout(seconds=900)
    def _test_gmail_1_with_extension(self):
    ....

The test class inherits from BaseSeleniumTestCase and runs the test. I can comment the decorators every time before I run the test in Windows, but I would like to have a better solution, without creating different tests. But it is possible to call another function which will check if we are in Windows or Linux, if we are in Windows it will run the test without the decorator and in Linux it will apply the decorator and run the test. Any suggestions?

Community
  • 1
  • 1
Uri
  • 2,992
  • 8
  • 43
  • 86
  • You need to check the internal implementation what `timeout_decorator` does. It most likely uses threads and those behave differently on Windows. Then take a look on Windows system programming and try to figure out can you make threads cancellable or not. Just a guess. – Mikko Ohtamaa Aug 31 '15 at 11:03
  • @MikkoOhtamaa They have two options but they both don't work on Windows. I just want to run the tests on Windows without the decorator. – Uri Aug 31 '15 at 11:05

1 Answers1

3

You can redefine timeout_decorator to accept the same signature and provide a no-op on windows:

import os

if os.name == 'nt':
    # We redefine timeout_decorator on windows
    class timeout_decorator:
        @staticmethod
        def timeout(*args, **kwargs):
            return lambda f: f # return a no-op decorator
else:
    import timeout_decorator

class BaseSeleniumTestCase(unittest.TestCase):
    ... # Keep your class intact
301_Moved_Permanently
  • 4,007
  • 14
  • 28