2014-04-09 06:40:30 +08:00
|
|
|
"""Test cucumber json output."""
|
|
|
|
import json
|
|
|
|
import textwrap
|
|
|
|
|
2014-05-11 21:26:10 +08:00
|
|
|
import pytest
|
|
|
|
|
2014-04-09 06:40:30 +08:00
|
|
|
|
|
|
|
def runandparse(testdir, *args):
|
|
|
|
"""Run tests in testdir and parse json output."""
|
|
|
|
resultpath = testdir.tmpdir.join("cucumber.json")
|
2014-05-11 19:18:43 +08:00
|
|
|
result = testdir.runpytest('--cucumberjson={0}'.format(resultpath), '-s', *args)
|
2014-05-11 17:26:18 +08:00
|
|
|
jsonobject = json.load(resultpath.open())
|
2014-04-09 06:40:30 +08:00
|
|
|
return result, jsonobject
|
|
|
|
|
|
|
|
|
2014-05-11 21:26:10 +08:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def equals_any():
|
|
|
|
"""Helper object comparison to which is always 'equal'."""
|
|
|
|
class equals_any(object):
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __cmp__(self, other):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
return equals_any()
|
|
|
|
|
|
|
|
|
2014-04-09 06:40:30 +08:00
|
|
|
def test_step_trace(testdir):
|
|
|
|
"""Test step trace."""
|
|
|
|
testdir.makefile('.feature', test=textwrap.dedent("""
|
|
|
|
Feature: One passing scenario, one failing scenario
|
|
|
|
|
|
|
|
Scenario: Passing
|
|
|
|
Given a passing step
|
|
|
|
|
|
|
|
Scenario: Failing
|
|
|
|
Given a failing step
|
|
|
|
"""))
|
|
|
|
testdir.makepyfile(textwrap.dedent("""
|
|
|
|
import pytest
|
|
|
|
from pytest_bdd import given, when, scenario
|
|
|
|
|
|
|
|
@given('a passing step')
|
|
|
|
def a_passing_step():
|
|
|
|
return 'pass'
|
|
|
|
|
|
|
|
@given('a failing step')
|
2014-05-11 17:21:09 +08:00
|
|
|
def a_failing_step():
|
2014-04-09 06:40:30 +08:00
|
|
|
raise Exception('Error')
|
|
|
|
|
|
|
|
@scenario('test.feature', 'Passing')
|
|
|
|
def test_passing():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@scenario('test.feature', 'Failing')
|
|
|
|
def test_failing():
|
|
|
|
pass
|
|
|
|
"""))
|
|
|
|
result, jsonobject = runandparse(testdir)
|
|
|
|
assert result.ret
|
|
|
|
assert jsonobject == [
|
|
|
|
{
|
|
|
|
"description": "",
|
|
|
|
"elements": [
|
|
|
|
{
|
|
|
|
"description": "",
|
2014-05-11 21:52:18 +08:00
|
|
|
"id": "test_passing",
|
2014-04-09 06:40:30 +08:00
|
|
|
"keyword": "Scenario",
|
|
|
|
"line": 5,
|
|
|
|
"name": "Passing",
|
|
|
|
"steps": [
|
|
|
|
{
|
|
|
|
"keyword": "Given ",
|
|
|
|
"line": 6,
|
|
|
|
"match": {
|
|
|
|
"location": "features/step_definitions/steps.rb:1"
|
|
|
|
},
|
|
|
|
"name": "a passing step",
|
|
|
|
"result": {
|
|
|
|
"status": "passed"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2014-05-11 22:05:13 +08:00
|
|
|
"tags": [],
|
2014-04-09 06:40:30 +08:00
|
|
|
"type": "scenario"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"description": "",
|
2014-05-11 21:52:18 +08:00
|
|
|
"id": "test_failing",
|
2014-04-09 06:40:30 +08:00
|
|
|
"keyword": "Scenario",
|
|
|
|
"line": 9,
|
|
|
|
"name": "Failing",
|
|
|
|
"steps": [
|
|
|
|
{
|
|
|
|
"keyword": "Given ",
|
|
|
|
"line": 10,
|
|
|
|
"match": {
|
|
|
|
"location": "features/step_definitions/steps.rb:5"
|
|
|
|
},
|
|
|
|
"name": "a failing step",
|
|
|
|
"result": {
|
|
|
|
"error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in /a "
|
|
|
|
"failing step/'\nfeatures/one_passing_one_failing.feature:10:in Given a failing step'",
|
|
|
|
"status": "failed"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"tags": [
|
|
|
|
{
|
|
|
|
"line": 8,
|
|
|
|
"name": "@c"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"type": "scenario"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"id": "one-passing-scenario,-one-failing-scenario",
|
|
|
|
"keyword": "Feature",
|
|
|
|
"line": 2,
|
|
|
|
"name": "One passing scenario, one failing scenario",
|
2014-05-11 21:37:18 +08:00
|
|
|
"tags": [],
|
2014-04-09 06:40:30 +08:00
|
|
|
"uri": "features/one_passing_one_failing.feature"
|
|
|
|
}
|
|
|
|
]
|