Skip to content

Instantly share code, notes, and snippets.

@necrolyte2
Last active August 29, 2015 14:07
Show Gist options
  • Save necrolyte2/1e12bca5ada9c41a57bf to your computer and use it in GitHub Desktop.
Save necrolyte2/1e12bca5ada9c41a57bf to your computer and use it in GitHub Desktop.
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 )
def example1(self):
return True
def example2(self):
return False
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