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 systemS
, this systemS
uses pythonunittest2
as the testing framework (however tweaked). Specifically, it implements a classA
, which inherits fromunittest2
and another customized exception handling classB
. All test are then implemented based onA
. SystemS
is available on Linux only. However, this softwareSF
is also used as a standalone application, which should only useunittest2
when we test it on other platforms, in which cases classA
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.