def _patched_load_step_definitions(self, extra_step_paths=None):
    steps_dir = os.path.join(self.base_dir, 'steps')
    if extra_step_paths is None:
        extra_step_paths = []
        for path in self.config.paths[1:]:
            dirname = os.path.abspath(path)
            for dirname, subdirs, _fnames in os.walk(dirname):
                if 'steps' in subdirs:
                    extra_step_paths.append(os.path.join(dirname, 'steps'))
                    subdirs.remove('steps') # prune search
    # allow steps to import other stuff from the steps dir
    sys.path.insert(0, steps_dir)

    step_globals = {
        'step_matcher': matchers.step_matcher,
    }

    for step_type in ('given', 'when', 'then', 'step'):
        decorator = getattr(step_registry, step_type)
        step_globals[step_type] = decorator
        step_globals[step_type.title()] = decorator

    for path in [steps_dir] + list(extra_step_paths):
        for name in os.listdir(path):
            if name.endswith('.py') and not name.startswith('.'):
                exec_file(os.path.join(path, name), step_globals)

    # clean up the path
    sys.path.pop(0)
Exemple #2
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, 'w') as f:
         f.write('spam = __file__\n')
     g = {}
     l = {}
     runner.exec_file(fn, g, l)
     assert '__file__' in l
     assert 'spam' in l, '"spam" variable not set in locals (%r)' % (g, l)
     eq_(l['spam'], fn)
Exemple #3
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, "w") as f:
         f.write("spam = __file__\n")
     g = {}
     l = {}
     runner.exec_file(fn, g, l)
     assert "__file__" in l
     assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
     eq_(l["spam"], fn)
Exemple #4
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, 'w') as f:
         f.write('spam = __file__\n')
     g = {}
     l = {}
     runner.exec_file(fn, g, l)
     assert '__file__' in l
     assert 'spam' in l, '"spam" variable not set in locals (%r)' % (g, l)
     eq_(l['spam'], fn)
Exemple #5
0
    def load_steps(self):

        step_globals = {'use_step_matcher': matchers.use_step_matcher,}
        setup_step_decorators(step_globals)
        default_matcher = matchers.current_matcher

        for file_path in glob.glob(self.config.plugins_dir + '/*/steps.py'):
            step_module_globals = step_globals.copy()
            exec_file(file_path, step_module_globals)
            matchers.current_matcher = default_matcher
Exemple #6
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, "w") as f:
         f.write("spam = __file__\n")
     g = {}
     l = {}
     runner.exec_file(fn, g, l)
     assert "__file__" in l
     # pylint: disable=too-many-format-args
     assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
     # pylint: enable=too-many-format-args
     eq_(l["spam"], fn)
Exemple #7
0
 def test_exec_file(self):
     fn = tempfile.mktemp()
     with open(fn, "w") as f:
         f.write("spam = __file__\n")
     g = {}
     l = {}
     runner.exec_file(fn, g, l)
     assert "__file__" in l
     # pylint: disable=too-many-format-args
     assert "spam" in l, '"spam" variable not set in locals (%r)' % (g, l)
     # pylint: enable=too-many-format-args
     eq_(l["spam"], fn)
Exemple #8
0
 def test_exec_file(self):
     # XXX-JE-ORIG, DEPRECATED: fn = tempfile.mktemp()
     # with open(fn, 'w') as f:
     #   f.write('spam = __file__\n')
     with named_temporary_file() as f:
         f.write('spam = __file__\n')
         f.close()
         g = {}
         l = {}
         runner.exec_file(f.name, g, l)
         assert '__file__' in l
         # XXX-JE-ORIG: assert 'spam' in l, '"spam" variable not set in locals (%r)' % (g, l)
         # XXX-JE-NOTE: Formatting mismatch: Too many args.
         assert 'spam' in l, '"spam" variable not set in locals (%r)' % l
         eq_(l['spam'], f.name)