Skip to content

Instantly share code, notes, and snippets.

@RobSpectre
Created April 19, 2011 21:51
Show Gist options
  • Save RobSpectre/929801 to your computer and use it in GitHub Desktop.
Save RobSpectre/929801 to your computer and use it in GitHub Desktop.
assertRaises WTF?
#Unit test that is failing.
class Test_BuildApp(unittest.TestCase):
def test_isNotApp(self):
build_fail = build.BuildApp(self.test_app_fail_path)
self.assertRaises(build.BuildAppException, build_fail.isApp())
# Code it is testing (in build.py)
class BuildApp:
def isApp(self):
if "/" in self.path:
self.app_dir = self.path.split("/").pop()
else:
self.app_dir = self.path
for root, dirs, files in os.walk(self.path):
if "descriptor.xml" in files:
return True
raise BuildAppException("Could not find descriptor.xml in path: %s" % (self.path), "BuildError")
# Exception it is raising (in build.py)
class BuildAppException(Exception):
def __init__(self, message, e):
Exception.__init__(self, message)
self.log = logging.getLogger("Exception")
self.log.addHandler(log_handler)
self.logError(message, e)
def logError(self, e, message):
return self.log.critical("%s! %s" % (str(e), message))
@RobSpectre
Copy link
Author

test_isNotApp fails even though BuildAppException is raised.

@RobSpectre
Copy link
Author

Problem child is line 5 - build_fail isApp() should be "build_fail.isApp". assertRaises takes a callable, not a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment