How to use different test package on different platforms

66 Views Asked by At

I come from a C++ background, my Python knowledge is very limited, I need help with the following situation:

Background:

We have a software SF, which is integrated into a large system S, this system S uses python unittest2 as the testing framework (however tweaked). Specifically, it implements a class A, which inherits from unittest2 and another customized exception handling class B. All test are then implemented based on A. System S is available on Linux only. However, this software SF is also used as a standalone application, which should only use unittest2 when we test it on other platforms, in which cases class A is not available.

Question:
How could I apply different test packages on different platforms?

My possible solution:
I am thinking of implementing a wrapper class based on this thread: Create a wrapper class to call a pre and post function around existing functions?. Answer from that post is put below:

class Wrapper(object):
    def __init__(self,wrapped_class):
        self.wrapped_class = wrapped_class()

    def __getattr__(self,attr):
        orig_attr = self.wrapped_class.__getattribute__(attr)
        if callable(orig_attr):
            def hooked(*args, **kwargs):
                self.pre()
                result = orig_attr(*args, **kwargs)
                # prevent wrapped_class from becoming unwrapped
                if result == self.wrapped_class:
                    return self
                self.post()
                return result
            return hooked
        else:
            return orig_attr    

However, I don't think the above thread is quite relevant since it is dealing with wrappers around class' member functions while I want some wrapper class that wrappers around different testing packages. Is it possible to do this in Python? I am using Python 2.7 FYI.

Any input is greatly appreciated and I am happy to add more information if it helps to make myself clear. Thank you.

0

There are 0 best solutions below