Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show params of scenario outline when verbose mode is enabled and for xunit plugin #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion freshen/noseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def options(self, parser, env):
help="Make a report of all undefined steps that "
"freshen encounters when running scenarios. "
"[NOSE_FRESHEN_LIST_UNDEFINED]")
parser.add_option('--scenario-outline-values',
action="store_true",
default=env.get('NOSE_FRESHEN_SCENARIO_OUTLINE_VALUES') == '1',
dest='scenario_outline_values',
help="Display parameters given for a scenario oultine "
"when they are not already present in the scenario "
"description. [NOSE_FRESHEN_SCENARIO_OUTLINE_VALUES]")

def configure(self, options, config):
super(FreshenNosePlugin, self).configure(options, config)
Expand All @@ -105,6 +112,7 @@ def configure(self, options, config):
self.undefined_steps = []
else:
self.undefined_steps = None
self.scenario_outline_values = options.scenario_outline_values
self._test_class = None

def wantDirectory(self, dirname):
Expand Down Expand Up @@ -166,7 +174,9 @@ def loadTestsFromFile(self, filename, indexes=[]):
if (not indexes or (i + 1) in indexes):
if self.tagmatcher.check_match(sc.tags + feat.tags):
test_class = self._makeTestClass(feat, sc)
yield test_class(StepsRunner(step_registry), step_registry, feat, sc, ctx)
test = test_class(StepsRunner(step_registry), step_registry, feat, sc, ctx)
test.show_all_scenario_params = self.scenario_outline_values
yield test
cnt += 1

if not cnt:
Expand Down Expand Up @@ -201,6 +211,7 @@ def _split_file_in_indexes(self, name_with_indexes):
indexes = []
indexes = set(int(p) for p in parts)
return (name_without_indexes, indexes)


def describeTest(self, test):
if isinstance(test.test, FreshenTestCase):
Expand Down
9 changes: 5 additions & 4 deletions freshen/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ def iter_steps(self):

class Scenario(object):

def __init__(self, tags, name, steps):
def __init__(self, tags, name, steps, params=None):
self.tags = tags
self.name = name
self.steps = steps
self.background = None
self.params = params

def __repr__(self):
return '<Scenario "%s">' % self.name
Expand Down Expand Up @@ -99,8 +100,8 @@ def iterate(self):
for values in ex.table.iterrows():
new_steps = []
for step in self.steps:
new_steps.append(step.set_values(values))
sc = Scenario(self.tags, self.name, new_steps)
new_steps.append(step.set_values(dict(values)))
sc = Scenario(self.tags, self.name, new_steps, values)
sc.feature = self.feature
sc.background = self.background
yield sc
Expand Down Expand Up @@ -147,7 +148,7 @@ def __repr__(self):

def iterrows(self):
for row in self.rows:
yield dict(zip(self.headings, row))
yield zip(self.headings, row)


def grammar(fname, l, convert=True, base_line=0):
Expand Down
43 changes: 41 additions & 2 deletions freshen/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import traceback
import sys
import re
import os

from freshen.context import ftc, scc
from freshen.stepregistry import UndefinedStepImpl
Expand Down Expand Up @@ -40,6 +42,7 @@ class FreshenTestCase(object):
django_plugin_started = False
http_plugin_started = False
last_step = None
re_scenario_outline_values = re.compile('<([^>]+)>')

test_type = "http"

Expand All @@ -49,8 +52,44 @@ def __init__(self, step_runner, step_registry, feature, scenario, feature_suite)
self.context = feature_suite
self.step_registry = step_registry
self.step_runner = step_runner

self.description = feature.name + ": " + scenario.name
self._description = None
self.show_all_scenario_params = False

def package(self):
pwd = os.getcwd()
path = os.path.splitext(self.feature.src_file[len(pwd)+1:])[0]
return path.split(os.path.sep)

@property
def description(self):
"""return a description of the test case.
This allow replacement of scenario outline name's.
if show_all_scenario_params is enabled, params not
present in the name are appended too.
"""
if not self._description:
desc = self.feature.name + ": " + self.scenario.name
params = self.scenario.params
if not params: return desc
keys = self.re_scenario_outline_values.findall(desc)
d_params = dict(params)
for k in keys:
val = d_params.get(k)
if val is not None:
desc = desc.replace('<%s>' % k, val)
if self.show_all_scenario_params:
resulting_params = ['%s=%s' % (p[0], p[1]) for p in params if p[0] not in keys]
if resulting_params:
desc = '%s (%s)' % (desc, ','.join(resulting_params))
self._description = desc
return self._description

def id(self):
"""return a description for xunit.
description is created with folders relative to the current directory
and the name of the feature file, then the feature name. All
these elements are separated with dots."""
return '.'.join(self.package() + [self.description])

def setUp(self):
#log.debug("Clearing scenario context")
Expand Down