def test_all_of_ignore_name(): class A(object): name = "long_name" value = "val" t = "ololo" assert_that(all_of(A), only_contains(("t", "ololo"), ))
def test_all_of_ignore_name(): class A(object): name = "long_name" value = "val" t = "ololo" assert_that(all_of(A), only_contains(("t", "ololo"),))
def pytest_addoption(parser): parser.getgroup("reporting").addoption('--alluredir', action="store", dest="allurereportdir", metavar="DIR", default=None, help="Generate Allure report in the specified directory (may not exist)") severities = [v for (_, v) in all_of(Severity)] def severity_type(string): entries = [x.strip() for x in string.split(',')] for entry in entries: if entry not in severities: raise argparse.ArgumentTypeError('Illegal severity value [%s], only values from [%s] are allowed.' % (entry, ', '.join(severities))) return entries parser.getgroup("general").addoption('--allure_severities', action="store", dest="allureseverities", metavar="SEVERITIES_LIST", default=None, type=severity_type, help="""Comma-separated list of severity names. Tests only with these severities will be run. Possible values are:%s.""" % ', '.join(severities))
def pytest_addoption(parser): parser.getgroup("reporting").addoption('--alluredir', action="store", dest="allurereportdir", metavar="DIR", default=None, help="Generate Allure report in the specified directory (may not exist)") severities = [v for (_, v) in all_of(Severity)] def label_type(name, legal_values=set()): """ argparse-type factory for labelish things. processed value is set of tuples (name, value). :param name: of label type (for future TestLabel things) :param legal_values: a `set` of values that are legal for this label, if any limit whatsoever :raises ArgumentTypeError: if `legal_values` are given and there are values that fall out of that """ def a_label_type(string): atoms = set(string.split(',')) if legal_values and not atoms < legal_values: raise argparse.ArgumentTypeError('Illegal {} values: {}, only [{}] are allowed'.format(name, ', '.join(atoms - legal_values), ', '.join(legal_values))) return set((name, v) for v in atoms) return a_label_type parser.getgroup("general").addoption('--allure_severities', action="store", dest="allureseverities", metavar="SEVERITIES_SET", default={}, type=label_type(name=Label.SEVERITY, legal_values=set(severities)), help="""Comma-separated list of severity names. Tests only with these severities will be run. Possible values are:%s.""" % ', '.join(severities)) parser.getgroup("general").addoption('--allure_features', action="store", dest="allurefeatures", metavar="FEATURES_SET", default={}, type=label_type(name=Label.FEATURE), help="""Comma-separated list of feature names. Run tests that have at least one of the specified feature labels.""") parser.getgroup("general").addoption('--allure_stories', action="store", dest="allurestories", metavar="STORIES_SET", default={}, type=label_type(name=Label.STORY), help="""Comma-separated list of story names. Run tests that have at least one of the specified story labels.""")
def pytest_addoption(parser): parser.getgroup("reporting").addoption('--alluredir', action="store", dest="allurereportdir", metavar="DIR", default=None, help="Generate Allure report in the specified directory (may not exist)") severities = [v for (_, v) in all_of(Severity)] def severity_label_type(string): entries = LabelsList([TestLabel(name=Label.SEVERITY, value=x) for x in string.split(',')]) for entry in entries: if entry.value not in severities: raise argparse.ArgumentTypeError('Illegal severity value [%s], only values from [%s] are allowed.' % (entry.value, ', '.join(severities))) return entries def features_label_type(string): return LabelsList([TestLabel(name=Label.FEATURE, value=x) for x in string.split(',')]) def stories_label_type(string): return LabelsList([TestLabel(name=Label.STORY, value=x) for x in string.split(',')]) parser.getgroup("general").addoption('--allure_severities', action="store", dest="allureseverities", metavar="SEVERITIES_LIST", default=LabelsList(), type=severity_label_type, help="""Comma-separated list of severity names. Tests only with these severities will be run. Possible values are:%s.""" % ', '.join(severities)) parser.getgroup("general").addoption('--allure_features', action="store", dest="allurefeatures", metavar="FEATURES_LIST", default=LabelsList(), type=features_label_type, help="""Comma-separated list of feature names. Run tests that have at least one of the specified feature labels.""") parser.getgroup("general").addoption('--allure_stories', action="store", dest="allurestories", metavar="STORIES_LIST", default=LabelsList(), type=stories_label_type, help="""Comma-separated list of story names. Run tests that have at least one of the specified story labels.""")
@pytest.mark.parametrize('package', ['pytest.allure', 'allure']) def test_smoke(report_for, package): report = report_for(""" import pytest import allure def test_x(): %s.attach('Foo', 'Bar') """ % package) assert_that(report.findall('test-cases/test-case/attachments/attachment'), contains(has_property('attrib', has_entries(title='Foo')))) @pytest.mark.parametrize('a_type', map(lambda x: x[0], all_of(AttachmentType))) def test_attach_types(report_for, a_type): report = report_for(""" import allure as A def test_x(): A.attach('Foo', 'Bar', A.attach_type.%s) """ % a_type) assert_that(report.find('.//attachment').attrib, has_entries(title='Foo', type=getattr(AttachmentType, a_type).mime_type)) class TestContents: @pytest.fixture def attach_contents(self, report_for, reportdir):
@pytest.mark.parametrize('package', ['pytest.allure', 'allure']) def test_smoke(report_for, package): report = report_for(""" import pytest import allure def test_x(): %s.attach('Foo', 'Bar') """ % package) assert_that(report.findall('test-cases/test-case/attachments/attachment'), contains(has_property('attrib', has_entries(title='Foo')))) @pytest.mark.parametrize('a_type', map(lambda x: x[0], all_of(AttachmentType))) def test_attach_types(report_for, a_type): report = report_for(""" import allure as A def test_x(): A.attach('Foo', 'Bar', A.attach_type.%s) """ % a_type) assert_that( report.find('.//attachment').attrib, has_entries(title='Foo', type=getattr(AttachmentType, a_type).mime_type)) class TestContents:
def pytest_addoption(parser): parser.getgroup("reporting").addoption( '--alluredir', action="store", dest="allurereportdir", metavar="DIR", default=None, help="Generate Allure report in the specified directory (may not exist)" ) severities = [v for (_, v) in all_of(Severity)] def severity_label_type(string): entries = LabelsList([ TestLabel(name=Label.SEVERITY, value=x) for x in string.split(',') ]) for entry in entries: if entry.value not in severities: raise argparse.ArgumentTypeError( 'Illegal severity value [%s], only values from [%s] are allowed.' % (entry.value, ', '.join(severities))) return entries def features_label_type(string): return LabelsList([ TestLabel(name=Label.FEATURE, value=x) for x in string.split(',') ]) def stories_label_type(string): return LabelsList( [TestLabel(name=Label.STORY, value=x) for x in string.split(',')]) parser.getgroup("general").addoption( '--allure_severities', action="store", dest="allureseverities", metavar="SEVERITIES_LIST", default=LabelsList(), type=severity_label_type, help="""Comma-separated list of severity names. Tests only with these severities will be run. Possible values are:%s.""" % ', '.join(severities)) parser.getgroup("general").addoption( '--allure_features', action="store", dest="allurefeatures", metavar="FEATURES_LIST", default=LabelsList(), type=features_label_type, help="""Comma-separated list of feature names. Run tests that have at least one of the specified feature labels.""" ) parser.getgroup("general").addoption( '--allure_stories', action="store", dest="allurestories", metavar="STORIES_LIST", default=LabelsList(), type=stories_label_type, help="""Comma-separated list of story names. Run tests that have at least one of the specified story labels.""" )
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('name,value', utils.all_of(Severity)) def test_method_severity(report_for, name, value, mark_way): report = report_for(""" import pytest %s def test_foo(): pass """ % (mark_way % name)) assert_that(report.findall(".//test-case/labels/label"), contains(severity_element(value))) def test_class_severity(report_for): """
from .matchers import has_label def severity_element(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('name,value', utils.all_of(Severity)) def test_method_severity(report_for, name, value, mark_way): report = report_for(""" import pytest %s def test_foo(): pass """ % (mark_way % name)) assert_that(report, has_test_with_severity('test_foo', value)) def test_class_severity(report_for): """ Checks that severity markers for tests override ones for class