Generation tests improved
This commit is contained in:
parent
440d669d1c
commit
38d3ad9e0a
|
@ -77,8 +77,10 @@ def print_missing_code(scenarios, steps):
|
|||
for scenario in scenarios:
|
||||
tw.line()
|
||||
tw.line(
|
||||
'Scenario is not bound to any test: "{scenario.name}" in feature "{scenario.feature.name}"'
|
||||
" in {scenario.feature.filename}.".format(scenario=scenario), red=True)
|
||||
'Scenario "{scenario.name}" is not bound to any test in the feature "{scenario.feature.name}"'
|
||||
" in the file {scenario.feature.filename}:{scenario.line_number}".format(scenario=scenario),
|
||||
red=True,
|
||||
)
|
||||
|
||||
if scenario:
|
||||
tw.sep("-", red=True)
|
||||
|
@ -87,14 +89,16 @@ def print_missing_code(scenarios, steps):
|
|||
tw.line()
|
||||
if step.scenario is not None:
|
||||
tw.line(
|
||||
"""Step is not defined: "{step.name}" in scenario: "{step.scenario.name}" in feature"""
|
||||
""" "{step.scenario.feature.name}" in {step.scenario.feature.filename}""".format(step=step),
|
||||
"""Step "{step.name}" is not defined in the scenario "{step.scenario.name}" in the feature"""
|
||||
""" "{step.scenario.feature.name}" in the file"""
|
||||
""" {step.scenario.feature.filename}:{step.line_number}""".format(step=step),
|
||||
red=True,
|
||||
)
|
||||
elif step.background is not None:
|
||||
tw.line(
|
||||
"""Step is not defined: "{step.name}" in feature"""
|
||||
""" "{step.background.feature.name}" in {step.background.feature.filename}""".format(step=step),
|
||||
"""Step "{step.name}" is not defined in the background of the feature"""
|
||||
""" "{step.background.feature.name}" in the file"""
|
||||
""" {step.background.feature.filename}:{step.line_number}""".format(step=step),
|
||||
red=True,
|
||||
)
|
||||
|
||||
|
@ -166,8 +170,9 @@ def parse_feature_files(paths):
|
|||
key=lambda scenario: (
|
||||
scenario.feature.name or scenario.feature.filename, scenario.name))
|
||||
steps = sorted(
|
||||
itertools.chain.from_iterable(scenario.steps for scenario in scenarios),
|
||||
key=lambda step: step.name)
|
||||
set(itertools.chain.from_iterable(scenario.steps for scenario in scenarios)),
|
||||
key=lambda step: step.name,
|
||||
)
|
||||
return features, scenarios, steps
|
||||
|
||||
|
||||
|
@ -212,7 +217,8 @@ def _show_missing_code_main(config, session):
|
|||
pass
|
||||
for scenario in scenarios:
|
||||
for step in scenario.steps:
|
||||
steps.remove(step)
|
||||
if step.background is None:
|
||||
steps.remove(step)
|
||||
print_missing_code(scenarios, steps)
|
||||
|
||||
if scenarios or steps:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
% if features:
|
||||
"""${ features[0].name or features[0].rel_filename } feature tests."""
|
||||
from functools import partial
|
||||
|
||||
from pytest_bdd import (
|
||||
given,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
Feature: Missing code generation
|
||||
|
||||
Background:
|
||||
Given I have a foobar
|
||||
|
||||
Scenario: Scenario tests which are already bound to the tests stay as is
|
||||
Given I have a bar
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Code generation and assertion tests."""
|
||||
|
||||
import os.path
|
||||
|
||||
import py
|
||||
|
@ -33,10 +34,18 @@ def test_generate_missing(testdir):
|
|||
"tests", "--generate-missing", "--feature", tests.join('generation.feature').strpath)
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
'Scenario is not bound to any test: "Code is generated for scenarios which are not bound to any tests" *'])
|
||||
'Scenario "Code is generated for scenarios which are not bound to any tests" is not bound to any test *']
|
||||
)
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
'Step is not defined: "I have a custom bar" in scenario: "Code is generated for scenario steps which are not '
|
||||
'yet defined(implemented)" *'])
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
'Step "I have a custom bar" is not defined in the scenario '
|
||||
'"Code is generated for scenario steps which are not yet defined(implemented)" *',
|
||||
]
|
||||
)
|
||||
|
||||
result.stdout.fnmatch_lines(
|
||||
['Step "I have a foobar" is not defined in the background of the feature "Missing code generation" *']
|
||||
)
|
||||
|
||||
result.stdout.fnmatch_lines(["Please place the code above to the test file(s):"])
|
||||
|
|
|
@ -15,7 +15,6 @@ def test_generate(monkeypatch, capsys):
|
|||
out, err = capsys.readouterr()
|
||||
assert out == textwrap.dedent('''
|
||||
"""Code generation feature tests."""
|
||||
from functools import partial
|
||||
|
||||
from pytest_bdd import (
|
||||
given,
|
||||
|
|
Loading…
Reference in New Issue