Commit ead2993f by Michel Sabchuk

Fixes #476, change the syntax of caught exceptions.

parent 19e6f8cd
...@@ -71,7 +71,7 @@ __all__ = [ ...@@ -71,7 +71,7 @@ __all__ = [
try: try:
terrain = fs.FileSystem._import("terrain") terrain = fs.FileSystem._import("terrain")
reload(terrain) reload(terrain)
except Exception, e: except Exception as e:
if not "No module named terrain" in str(e): if not "No module named terrain" in str(e):
string = 'Lettuce has tried to load the conventional environment ' \ string = 'Lettuce has tried to load the conventional environment ' \
'module "terrain"\nbut it has errors, check its contents and ' \ 'module "terrain"\nbut it has errors, check its contents and ' \
...@@ -161,7 +161,7 @@ class Runner(object): ...@@ -161,7 +161,7 @@ class Runner(object):
# that we don't even want to test. # that we don't even want to test.
try: try:
self.loader.find_and_load_step_definitions() self.loader.find_and_load_step_definitions()
except StepLoadingError, e: except StepLoadingError as e:
print "Error loading step definitions:\n", e print "Error loading step definitions:\n", e
return return
......
...@@ -143,7 +143,7 @@ class StepDefinition(object): ...@@ -143,7 +143,7 @@ class StepDefinition(object):
try: try:
ret = self.function(self.step, *args, **kw) ret = self.function(self.step, *args, **kw)
self.step.passed = True self.step.passed = True
except Exception, e: except Exception as e:
self.step.failed = True self.step.failed = True
self.step.why = ReasonToFail(self.step, e) self.step.why = ReasonToFail(self.step, e)
raise raise
...@@ -479,10 +479,10 @@ class Step(object): ...@@ -479,10 +479,10 @@ class Step(object):
step.run(ignore_case) step.run(ignore_case)
steps_passed.append(step) steps_passed.append(step)
except NoDefinitionFound, e: except NoDefinitionFound as e:
steps_undefined.append(e.step) steps_undefined.append(e.step)
except Exception, e: except Exception as e:
steps_failed.append(step) steps_failed.append(step)
reasons_to_fail.append(step.why) reasons_to_fail.append(step.why)
if failfast: if failfast:
...@@ -885,7 +885,7 @@ class Background(object): ...@@ -885,7 +885,7 @@ class Background(object):
call_hook('before_each', 'step', step) call_hook('before_each', 'step', step)
try: try:
results.append(step.run(ignore_case)) results.append(step.run(ignore_case))
except Exception, e: except Exception as e:
print e print e
pass pass
......
...@@ -162,7 +162,7 @@ class Command(BaseCommand): ...@@ -162,7 +162,7 @@ class Command(BaseCommand):
if run_server: if run_server:
try: try:
server.start() server.start()
except LettuceServerException, e: except LettuceServerException as e:
raise SystemExit(e) raise SystemExit(e)
os.environ['SERVER_NAME'] = str(server.address) os.environ['SERVER_NAME'] = str(server.address)
...@@ -196,10 +196,10 @@ class Command(BaseCommand): ...@@ -196,10 +196,10 @@ class Command(BaseCommand):
results.append(result) results.append(result)
if not result or result.steps != result.steps_passed: if not result or result.steps != result.steps_passed:
failed = True failed = True
except SystemExit, e: except SystemExit as e:
failed = e.code failed = e.code
except Exception, e: except Exception as e:
failed = True failed = True
import traceback import traceback
traceback.print_exc(e) traceback.print_exc(e)
......
...@@ -48,7 +48,7 @@ class FeatureLoader(object): ...@@ -48,7 +48,7 @@ class FeatureLoader(object):
to_load = FileSystem.filename(filename, with_extension=False) to_load = FileSystem.filename(filename, with_extension=False)
try: try:
module = __import__(to_load) module = __import__(to_load)
except ValueError, e: except ValueError as e:
import traceback import traceback
err_msg = traceback.format_exc(e) err_msg = traceback.format_exc(e)
if 'empty module name' in err_msg.lower(): if 'empty module name' in err_msg.lower():
...@@ -144,7 +144,7 @@ class FileSystem(object): ...@@ -144,7 +144,7 @@ class FileSystem(object):
""" """
try: try:
os.makedirs(path) os.makedirs(path)
except OSError, e: except OSError as e:
# ignore if path already exists # ignore if path already exists
if e.errno not in (17, ): if e.errno not in (17, ):
raise e raise e
......
...@@ -133,7 +133,7 @@ def call_hook(situation, kind, *args, **kw): ...@@ -133,7 +133,7 @@ def call_hook(situation, kind, *args, **kw):
for callback in CALLBACK_REGISTRY[kind][situation]: for callback in CALLBACK_REGISTRY[kind][situation]:
try: try:
callback(*args, **kw) callback(*args, **kw)
except Exception, e: except Exception as e:
print "=" * 1000 print "=" * 1000
traceback.print_exc(e) traceback.print_exc(e)
print print
......
...@@ -12,7 +12,7 @@ def get_url(url): ...@@ -12,7 +12,7 @@ def get_url(url):
try: try:
world.last_response = urllib2.urlopen(url) world.last_response = urllib2.urlopen(url)
except Exception, e: except Exception as e:
world.last_response = e world.last_response = e
return world.last_response return world.last_response
......
...@@ -14,7 +14,7 @@ def get_url(url): ...@@ -14,7 +14,7 @@ def get_url(url):
try: try:
world.last_response = urllib2.urlopen(url) world.last_response = urllib2.urlopen(url)
except Exception, e: except Exception as e:
world.last_response = e world.last_response = e
return world.last_response return world.last_response
......
...@@ -226,7 +226,7 @@ def test_hashes__first_attr_raises_assertion_error_if_empty(): ...@@ -226,7 +226,7 @@ def test_hashes__first_attr_raises_assertion_error_if_empty():
try: try:
step.hashes.first step.hashes.first
failed = False failed = False
except AssertionError, e: except AssertionError as e:
failed = True failed = True
assert_equals( assert_equals(
unicode(e), unicode(e),
...@@ -253,7 +253,7 @@ def test_hashes__last_attr_raises_assertion_error_if_empty(): ...@@ -253,7 +253,7 @@ def test_hashes__last_attr_raises_assertion_error_if_empty():
try: try:
step.hashes.last step.hashes.last
failed = False failed = False
except AssertionError, e: except AssertionError as e:
failed = True failed = True
assert_equals( assert_equals(
unicode(e), unicode(e),
...@@ -276,7 +276,7 @@ def test_handy_function_for_table_members_fail_giving_assertionerror(): ...@@ -276,7 +276,7 @@ def test_handy_function_for_table_members_fail_giving_assertionerror():
try: try:
step.hashes.values_under('Foobar') step.hashes.values_under('Foobar')
failed = False failed = False
except AssertionError, e: except AssertionError as e:
failed = True failed = True
assert_equals( assert_equals(
unicode(e), unicode(e),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment