Skip to content

Commit

Permalink
supporting pdb out of the box. closes #250
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfalcao committed Jan 28, 2013
1 parent dabe2cd commit d79ed12
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lettuce/__init__.py
Expand Up @@ -41,7 +41,10 @@
from lettuce.registry import STEP_REGISTRY
from lettuce.registry import CALLBACK_REGISTRY
from lettuce.exceptions import StepLoadingError
from lettuce.plugins import xunit_output
from lettuce.plugins import (
xunit_output,
autopdb
)
from lettuce import fs
from lettuce import exceptions

Expand Down Expand Up @@ -84,7 +87,7 @@ class Runner(object):
"""
def __init__(self, base_path, scenarios=None, verbosity=0, random=False,
enable_xunit=False, xunit_filename=None, tags=None,
failfast=False):
failfast=False, auto_pdb=False):
""" lettuce.Runner will try to find a terrain.py file and
import it from within `base_path`
"""
Expand All @@ -101,6 +104,8 @@ def __init__(self, base_path, scenarios=None, verbosity=0, random=False,
self.verbosity = verbosity
self.scenarios = scenarios and map(int, scenarios.split(",")) or None
self.failfast = failfast
if auto_pdb:
autopdb.enable(self)

sys.path.remove(base_path)

Expand Down
7 changes: 7 additions & 0 deletions lettuce/bin.py
Expand Up @@ -72,6 +72,12 @@ def main(args=sys.argv[1:]):
action="store_true",
help='Stop running in the first failure')

parser.add_option("--pdb",
dest="auto_pdb",
default=False,
action="store_true",
help='Launches an interactive debugger upon error')

options, args = parser.parse_args(args)
if args:
base_path = os.path.abspath(args[0])
Expand All @@ -93,6 +99,7 @@ def main(args=sys.argv[1:]):
enable_xunit=options.enable_xunit,
xunit_filename=options.xunit_file,
failfast=options.failfast,
auto_pdb=options.auto_pdb,
tags=tags,
)

Expand Down
6 changes: 5 additions & 1 deletion lettuce/django/management/commands/harvest.py
Expand Up @@ -76,6 +76,9 @@ class Command(BaseCommand):

make_option("--failfast", dest="failfast", default=False,
action="store_true", help='Stop running in the first failure'),

make_option("--pdb", dest="auto_pdb", default=False,
action="store_true", help='Launches an interactive debugger upon error'),
)

def stopserver(self, failed=False):
Expand Down Expand Up @@ -105,6 +108,7 @@ def handle(self, *args, **options):
run_server = not options.get('no_server', False)
tags = options.get('tags', None)
failfast = options.get('failfast', False)
auto_pdb = options.get('auto_pdb', False)

server = Server(port=options['port'])

Expand Down Expand Up @@ -134,7 +138,7 @@ def handle(self, *args, **options):
runner = Runner(path, options.get('scenarios'), verbosity,
enable_xunit=options.get('enable_xunit'),
xunit_filename=options.get('xunit_file'),
tags=tags, failfast=failfast)
tags=tags, failfast=failfast, auto_pdb=auto_pdb)

result = runner.run()
if app_module is not None:
Expand Down
33 changes: 33 additions & 0 deletions lettuce/plugins/autopdb.py
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from lettuce.terrain import after


def enable(runner):
@after.each_step
def failfast_or_pdb(step):
has_traceback = step.why

if not has_traceback:
return

sys.stdout.write(step.why.traceback + '\n')

try:
from IPython.core.debugger import Pdb
pdb = Pdb()
except ImportError:
try:
from IPython.Debugger import Pdb
from IPython.Shell import IPShell
IPShell(argv=[''])
pdb = Pdb()
except ImportError:
import pdb

matched, defined = step.pre_run(False)
if matched:
args = matched.groups()
kwargs = matched.groupdict()
pdb.runcall(defined.function, step, *args, **kwargs)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -29,7 +29,7 @@ def get_packages():

return packages

required_modules = ['sure', 'fuzzywuzzy']
required_modules = ['sure', 'fuzzywuzzy', 'ipdb']

if sys.version_info[:2] < (2, 6):
required_modules.append('multiprocessing')
Expand Down

0 comments on commit d79ed12

Please sign in to comment.