How to distribute and execute unit tests on the platform?

We have a python project that we want to start using buildbot. Its unit tests include tests that should only work on some platforms. So, we have tests that must be run on all platforms, tests that must run on only one particular platform, tests that must run on platforms A, B, C, and tests that run on B and D.

What is the best way to do this? Simple suites will be a hassle, as, as described, each test may have a different list of target platforms. I thought about adding the @run_on and @ignore_on decorators, which matched the platforms for testing methods. Anything better?

+5
source share
3 answers

We decided to go with decorators who, using the platform module and others, check if tests should be performed, and if not just let it pass (although we saw that python2.7 already has a skin test in its trunk that can be raised in such cases, to ignore the test).

0
source

Several times I used this very simple approach in test modules:

import sys
import unittest

if 'win' in sys.platform:
    class TestIt(unittest.TestCase):
        ...

if 'linux' in sys.platform:
    class TestIt(unittest.TestCase):
        ...
+2
source

.

http://docs.python.org/library/unittest.html#unittest.TestLoader.loadTestsFromName

, , , .

A, AIX, Linux () 32- Windows, B, Windows 64, Linux 64 Solaris, C, , HPUX D, ... ?

class TestA_AIX_Linux2_Win32( unittest.TestCase ):

class TestB_Win64_Linux64_Solaris( unittest.TestCase ):

class TestC_AIX_Linux2_Win32_Win64_Linux64_Solaris( unittest.TestCase ):

class TestD_All( unittest.TestCase ):

- " HP/UX". . , HP/UX. .

"" - , .

-

class TextC_XHPUX( unittest.TestCase ):

"_someOSName"; , "_X".

"We cannot have a positive OS list. What if we add a new OS? Do we need to rename each test to explicitly enable it?" Yes. The market for new operating systems is slowly developing, it is not so painful to manage.

An alternative is to include information in each class (for example, a class level function) or a decorator and use a specialized class loader that evaluates the class level function.

0
source

All Articles