Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #56 from allure-framework/pending_cancelled
Browse files Browse the repository at this point in the history
Report skips as CANCEL and xfail as PENDING
  • Loading branch information
mavlyutov committed Feb 5, 2015
2 parents e1106f2 + a2eb67f commit 0ee5e58
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 38 deletions.
6 changes: 5 additions & 1 deletion allure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import uuid

from _pytest.runner import Skipped
from _pytest.skipping import XFailed

from lxml import etree
import py

Expand All @@ -35,7 +37,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self.allure:
if exc_type is not None:
if exc_type == Skipped:
self.step.status = Status.SKIPPED
self.step.status = Status.CANCELED
elif exc_type == XFailed:
self.step.status = Status.PENDING
else:
self.step.status = Status.FAILED
else:
Expand Down
2 changes: 1 addition & 1 deletion allure/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Status(object):
FAILED = 'failed'
BROKEN = 'broken'
PASSED = 'passed'
SKIPPED = 'canceled'
CANCELED = 'canceled'
PENDING = 'pending'

Expand Down Expand Up @@ -51,3 +50,4 @@ def __init__(self, mime_type, extension):
ALLURE_NAMESPACE = "urn:model.allure.qatools.yandex.ru"
COMMON_NAMESPACE = "urn:model.commons.qatools.yandex.ru"
FAILED_STATUSES = [Status.FAILED, Status.BROKEN]
SKIPPED_STATUSES = [Status.CANCELED, Status.PENDING]
11 changes: 7 additions & 4 deletions allure/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from allure.common import AllureImpl, StepContext
from allure.utils import LabelsList
from allure.constants import Status, AttachmentType, Severity, \
FAILED_STATUSES, Label
FAILED_STATUSES, Label, SKIPPED_STATUSES
from allure.utils import parent_module, parent_down_from_module, labels_of, \
all_of, get_exception_message
from allure.structure import TestLabel
Expand Down Expand Up @@ -263,7 +263,7 @@ def _stop_case(self, report, status=None):
self.impl.stop_case(status,
message=get_exception_message(report),
trace=report.longrepr or report.wasxfail)
elif status == Status.SKIPPED:
elif status in SKIPPED_STATUSES:
skip_message = type(report.longrepr) == tuple and \
report.longrepr[2] or report.wasxfail
trim_msg_len = 89
Expand Down Expand Up @@ -305,7 +305,10 @@ def pytest_runtest_logreport(self, report):
else:
self._stop_case(report, status=Status.FAILED)
elif report.skipped:
self._stop_case(report, status=Status.SKIPPED)
if hasattr(report, 'wasxfail'):
self._stop_case(report, status=Status.PENDING)
else:
self._stop_case(report, status=Status.CANCELED)

def pytest_runtest_makereport(self, item, call, __multicall__): # @UnusedVariable
"""
Expand Down Expand Up @@ -344,7 +347,7 @@ def pytest_collectreport(self, report):
if report.failed:
status = Status.BROKEN
else:
status = Status.SKIPPED
status = Status.CANCELED

self.fails.append(CollectFail(name=mangle_testnames(report.nodeid.split("::"))[-1],
status=status,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


PACKAGE = "pytest-allure-adaptor"
VERSION = "1.5.2"
VERSION = "1.5.3"


def read(fname):
Expand Down
3 changes: 1 addition & 2 deletions tests/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def _matches(self, item):
return self.str_matcher.matches(float(item))

def describe_to(self, description):
description.append_text('an object with float ') \
.append_description_of(self.str_matcher)
description.append_text('an object with float ').append_description_of(self.str_matcher)


def has_float(match):
Expand Down
35 changes: 18 additions & 17 deletions tests/test_severity.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
@author: pupssman
"""

from __future__ import absolute_import
from hamcrest import assert_that, contains, all_of, has_entry, has_property, has_properties, contains_inanyorder, has_item, equal_to

import pytest

from hamcrest import assert_that, contains, all_of, has_entry, has_property, has_properties

from allure.constants import Severity, Status
from allure import utils
from .matchers import has_label
import pytest


def severity_element(value):
return has_properties(attrib=all_of(
has_entry('name', 'severity'),
has_entry('value', value)))
return has_properties(attrib=all_of(has_entry('name', 'severity'),
has_entry('value', value)))


def has_test_with_severity(test_name, severity_level):
return has_label(test_name, label_value=severity_level, label_name='severity')


@pytest.mark.parametrize('mark_way', [
'@pytest.allure.%s',
'@pytest.allure.severity(pytest.allure.severity_level.%s)'
], ids=['Short', 'Full'])
@pytest.mark.parametrize('mark_way', ['@pytest.allure.%s',
'@pytest.allure.severity(pytest.allure.severity_level.%s)'
], ids=['Short', 'Full'])
@pytest.mark.parametrize('name,value', utils.all_of(Severity))
def test_method_severity(report_for, name, value, mark_way):
report = report_for("""
Expand Down Expand Up @@ -104,13 +106,12 @@ def test_b(self):
))


@pytest.mark.parametrize('severities', [
[Severity.CRITICAL],
[Severity.CRITICAL, Severity.MINOR],
[Severity.CRITICAL, Severity.MINOR, Severity.NORMAL],
[Severity.TRIVIAL],
[Severity.BLOCKER],
])
@pytest.mark.parametrize('severities', [[Severity.CRITICAL],
[Severity.CRITICAL, Severity.MINOR],
[Severity.CRITICAL, Severity.MINOR, Severity.NORMAL],
[Severity.TRIVIAL],
[Severity.BLOCKER],
])
def test_run_only(report_for, severities):
"""
Checks that running for given severities runs only selected tests
Expand All @@ -130,7 +131,7 @@ def test_c():
pass
""", extra_run_args=['--allure_severities', ','.join(severities)])

a_status, b_status, c_status = [Status.PASSED if s in severities else Status.SKIPPED for s in [Severity.CRITICAL, Severity.MINOR, '']]
a_status, b_status, c_status = [Status.PASSED if s in severities else Status.CANCELED for s in [Severity.CRITICAL, Severity.MINOR, '']]

assert_that(report.xpath(".//test-case"), contains(
all_of(has_property('name', 'test_a'), has_property('attrib', has_entry('status', a_status))),
Expand Down
10 changes: 5 additions & 5 deletions tests/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
def step_with(name, start, stop, status):
return has_properties(name=name,
title=name,
attrib=all_of(
has_entry('start', has_float(greater_than_or_equal_to(start))),
has_entry('stop', has_float(less_than_or_equal_to(stop))),
has_entry('status', status)))
attrib=all_of(has_entry('start', has_float(greater_than_or_equal_to(start))),
has_entry('stop', has_float(less_than_or_equal_to(stop))),
has_entry('status', status)))


@pytest.fixture()
Expand All @@ -41,7 +40,8 @@ def impl(*a, **kw):

@pytest.mark.parametrize('status,expr', [(Status.PASSED, 'assert True'),
(Status.FAILED, 'assert False'),
(Status.SKIPPED, 'pytest.skip("foo")')])
(Status.CANCELED, 'pytest.skip("foo")'),
(Status.PENDING, 'pytest.xfail("foo")'), ])
def test_one_step(timed_report_for, status, expr):
report, start, stop = timed_report_for("""
import pytest
Expand Down
22 changes: 15 additions & 7 deletions tests/test_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
@author: pupssman
"""

from hamcrest import has_property, assert_that, has_properties, has_string
from hamcrest import has_property, assert_that, has_properties, has_string, has_entry, all_of
from hamcrest.library.text.stringcontainsinorder import string_contains_in_order

from allure.constants import Status

def has_error(message='', trace=''):

def has_error(message='', trace='', status=Status.FAILED):
return has_property('{}test-cases',
has_property('test-case',
has_property('failure',
has_properties({
'message': message,
'stack-trace': has_string(trace)
}))))
all_of(has_property('attrib', has_entry('status', status)),
has_property('failure',
has_properties({'message': message,
'stack-trace': has_string(trace)
})))))


def test_smoke(report_for):
Expand Down Expand Up @@ -45,6 +47,7 @@ def test_X(FOO):
""")

assert_that(report, has_error(message='RuntimeError: ololo',
status=Status.BROKEN,
trace=string_contains_in_order('FOO',
'raise',
'RuntimeError("ololo")',
Expand All @@ -58,6 +61,7 @@ def test_X(FOO):
""")

assert_that(report, has_error(message=string_contains_in_order('FixtureLookupError'),
status=Status.BROKEN,
trace=string_contains_in_order("fixture 'FOO' not found",
'available fixtures',)))

Expand All @@ -69,6 +73,7 @@ def test_Y():
""")

assert_that(report, has_error(message='failed',
status=Status.BROKEN,
trace=string_contains_in_order('import',
'SyntaxError')))

Expand Down Expand Up @@ -96,6 +101,7 @@ def test_Y():
""")

assert_that(report, has_error(message='ololo',
status=Status.PENDING,
trace=''))


Expand All @@ -108,6 +114,7 @@ def test_Y():
""")

assert_that(report, has_error(message='Skipped: ololo',
status=Status.CANCELED,
trace=''))


Expand All @@ -120,4 +127,5 @@ def test_Y():
""")

assert_that(report, has_error(message='Skipped: ' + 'ololo' * 16 + '...',
status=Status.CANCELED,
trace='Skipped: ' + 'ololo' * 16 + '!'))

0 comments on commit 0ee5e58

Please sign in to comment.