Commit 8f427a54 by Gabriel Falcão

Merge pull request #466 from dnozay/root_dir

add --root-dir option so discovery does not go up all the way to '/'
parents bd2c007c 910f08b0
...@@ -94,7 +94,7 @@ class Runner(object): ...@@ -94,7 +94,7 @@ class Runner(object):
enable_xunit=False, xunit_filename=None, enable_xunit=False, xunit_filename=None,
enable_subunit=False, subunit_filename=None, enable_subunit=False, subunit_filename=None,
tags=None, failfast=False, auto_pdb=False, tags=None, failfast=False, auto_pdb=False,
smtp_queue=None): smtp_queue=None, root_dir=None):
""" lettuce.Runner will try to find a terrain.py file and """ lettuce.Runner will try to find a terrain.py file and
import it from within `base_path` import it from within `base_path`
...@@ -108,7 +108,7 @@ class Runner(object): ...@@ -108,7 +108,7 @@ class Runner(object):
base_path = os.path.dirname(base_path) base_path = os.path.dirname(base_path)
sys.path.insert(0, base_path) sys.path.insert(0, base_path)
self.loader = fs.FeatureLoader(base_path) self.loader = fs.FeatureLoader(base_path, root_dir)
self.verbosity = verbosity self.verbosity = verbosity
self.scenarios = scenarios and map(int, scenarios.split(",")) or None self.scenarios = scenarios and map(int, scenarios.split(",")) or None
self.failfast = failfast self.failfast = failfast
......
...@@ -59,6 +59,13 @@ def main(args=sys.argv[1:]): ...@@ -59,6 +59,13 @@ def main(args=sys.argv[1:]):
default=False, default=False,
help="Run scenarios in a more random order to avoid interference") help="Run scenarios in a more random order to avoid interference")
parser.add_option("--root-dir",
dest="root_dir",
default="/",
type="string",
help="Tells lettuce not to search for features/steps "
" above this directory.")
parser.add_option("--with-xunit", parser.add_option("--with-xunit",
dest="enable_xunit", dest="enable_xunit",
action="store_true", action="store_true",
...@@ -121,6 +128,7 @@ def main(args=sys.argv[1:]): ...@@ -121,6 +128,7 @@ def main(args=sys.argv[1:]):
failfast=options.failfast, failfast=options.failfast,
auto_pdb=options.auto_pdb, auto_pdb=options.auto_pdb,
tags=tags, tags=tags,
root_dir=options.root_dir,
) )
result = runner.run() result = runner.run()
......
...@@ -30,17 +30,23 @@ from os.path import abspath, join, dirname, curdir, exists ...@@ -30,17 +30,23 @@ from os.path import abspath, join, dirname, curdir, exists
class FeatureLoader(object): class FeatureLoader(object):
"""Loader class responsible for findind features and step """Loader class responsible for findind features and step
definitions along a given path on filesystem""" definitions along a given path on filesystem"""
def __init__(self, base_dir): def __init__(self, base_dir, root_dir=None):
self.base_dir = FileSystem.abspath(base_dir) self.base_dir = FileSystem.abspath(base_dir)
if root_dir is None:
root_dir = '/'
self.root_dir = FileSystem.abspath(root_dir)
def find_and_load_step_definitions(self): def find_and_load_step_definitions(self):
# find steps, possibly up several directories # find steps, possibly up several directories
base_dir = self.base_dir base_dir = self.base_dir
while base_dir != '/': while base_dir != self.root_dir:
files = FileSystem.locate(base_dir, '*.py') files = FileSystem.locate(base_dir, '*.py')
if files: if files:
break break
base_dir = FileSystem.join(base_dir, '..') base_dir = FileSystem.join(base_dir, '..')
else:
# went as far as root_dir, also discover files under root_dir
files = FileSystem.locate(base_dir, '*.py')
for filename in files: for filename in files:
root = FileSystem.dirname(filename) root = FileSystem.dirname(filename)
......
...@@ -181,7 +181,7 @@ def test_after_each_all_is_executed_before_each_all(): ...@@ -181,7 +181,7 @@ def test_after_each_all_is_executed_before_each_all():
mox.StubOutWithMock(lettuce.fs, 'FileSystem') mox.StubOutWithMock(lettuce.fs, 'FileSystem')
mox.StubOutWithMock(lettuce, 'Feature') mox.StubOutWithMock(lettuce, 'Feature')
lettuce.fs.FeatureLoader('some_basepath').AndReturn(loader_mock) lettuce.fs.FeatureLoader('some_basepath', None).AndReturn(loader_mock)
lettuce.sys.path.insert(0, 'some_basepath') lettuce.sys.path.insert(0, 'some_basepath')
lettuce.sys.path.remove('some_basepath') lettuce.sys.path.remove('some_basepath')
......
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