Last active
August 29, 2015 14:07
-
-
Save necrolyte2/1e12bca5ada9c41a57bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tempdir | |
class BaseTester(object): | |
def setUp(self): | |
''' Auto enter temporary directory ''' | |
self.tdir = tempdir.TempDir() | |
os.chdir(self.tdir.name) | |
def tearDown(self): | |
''' Clean up the tempdir after test ''' | |
self.tdir.dissolve() | |
def _C( self, *args, **kwargs): | |
''' | |
Set modulepath as instance variable to be the name of the module | |
Set functionname as instance variable to automagically run that function | |
with self._C | |
''' | |
m = __import__( self.modulepath, fromlist=[self.functionname] ) | |
return getattr(m,self.functionname)( *args, **kwargs ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def example1(self): | |
return True | |
def example2(self): | |
return False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from basetester import BaseTester | |
class Base(BaseTester): | |
modulepath = 'example' | |
class TestExample1(BaseTester): | |
functionname = 'example1' | |
def test_is_true(self): | |
eq_( self._C(), True ) | |
class TestExample2(BaseTester): | |
functionname = 'example2' | |
def test_is_false(self): | |
eq_( self._C(), False ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment