Beispiel #1
0
def test_xml_exporter(tmpdir):
    """
        XMLExporter should create a JUnit compatible xml file for each
        multitest in the plan.
    """
    xml_dir = tmpdir.mkdir("xml")

    plan = Testplan(
        name="plan",
        parse_cmdline=False,
        exporters=XMLExporter(xml_dir=xml_dir.strpath),
    )
    multitest_1 = multitest.MultiTest(name="Primary", suites=[Alpha()])
    multitest_2 = multitest.MultiTest(name="Secondary", suites=[Beta()])
    plan.add(multitest_1)
    plan.add(multitest_2)
    plan.run()

    xml_primary = xml_dir.join("primary.xml").strpath
    xml_secondary = xml_dir.join("secondary.xml").strpath

    xml_primary_comparison = XC(
        tag="testsuites",
        children=[
            XC(
                tag="testsuite",
                tests="2",
                errors="0",
                name="Alpha",
                package="Primary:Alpha",
                hostname=re.compile(".+"),
                failures="0",
                id="0",
                children=[
                    XC(
                        tag="testcase",
                        classname="Primary:Alpha:test_comparison",
                        name="test_comparison",
                        time=re.compile(r"\d+\.?\d*"),
                    ),
                    XC(
                        tag="testcase",
                        classname="Primary:Alpha:test_membership",
                        name="test_membership",
                        time=re.compile(r"\d+\.?\d*"),
                    ),
                ],
            )
        ],
    )

    xml_secondary_comparison = XC(
        tag="testsuites",
        children=[
            XC(
                tag="testsuite",
                tests="2",
                errors="1",
                name="Beta",
                package="Secondary:Beta",
                hostname=re.compile(".+"),
                failures="1",
                id="0",
                children=[
                    XC(
                        tag="testcase",
                        classname="Secondary:Beta:test_failure",
                        name="test_failure",
                        time=re.compile(r"\d+\.?\d*"),
                        children=[
                            XC(
                                tag="failure",
                                message="failing assertion",
                                type="assertion",
                            ),
                            XC(
                                tag="failure",
                                message="Equal",
                                type="assertion",
                            ),
                        ],
                    ),
                    XC(
                        tag="testcase",
                        classname="Secondary:Beta:test_error",
                        name="test_error",
                        time=re.compile(r"\d+\.?\d*"),
                        children=[
                            XC(
                                tag="error",
                                message=re.compile(
                                    r"Traceback(.|\s)+Exception:\sfoo"),
                            )
                        ],
                    ),
                ],
            )
        ],
    )

    test_ctx = (
        (xml_primary, xml_primary_comparison),
        (xml_secondary, xml_secondary_comparison),
    )

    for file_path, xml_comparison in test_ctx:
        with open(file_path) as xml_file:
            xml_comparison.compare(xml_file.read())
Beispiel #2
0
def test_xml_exporter(tmpdir):
    """
        XMLExporter should create a JUnit compatible xml file for each
        multitest in the plan.
    """
    xml_dir = tmpdir.mkdir('xml')

    with log_propagation_disabled(TESTPLAN_LOGGER):
        plan = Testplan(name='plan',
                        parse_cmdline=False,
                        exporters=XMLExporter(xml_dir=xml_dir.strpath))
        multitest_1 = MultiTest(name='Primary', suites=[Alpha()])
        multitest_2 = MultiTest(name='Secondary', suites=[Beta()])
        plan.add(multitest_1)
        plan.add(multitest_2)
        plan.run()

    xml_primary = xml_dir.join('primary.xml').strpath
    xml_secondary = xml_dir.join('secondary.xml').strpath

    xml_primary_comparison = XC(
        tag='testsuites',
        children=[
            XC(tag='testsuite',
               tests="2",
               errors="0",
               name="Alpha",
               package="Primary:Alpha",
               hostname=re.compile(".+"),
               failures="0",
               id="0",
               children=[
                   XC(tag='testcase',
                      classname='Primary:Alpha:test_comparison',
                      name='test_comparison',
                      time=re.compile('\d+\.?\d*')),
                   XC(tag='testcase',
                      classname='Primary:Alpha:test_membership',
                      name='test_membership',
                      time=re.compile('\d+\.?\d*')),
               ]),
        ])

    xml_secondary_comparison = XC(
        tag='testsuites',
        children=[
            XC(tag='testsuite',
               tests="2",
               errors="1",
               name="Beta",
               package="Secondary:Beta",
               hostname=re.compile(".+"),
               failures="1",
               id="0",
               children=[
                   XC(
                       tag='testcase',
                       classname='Secondary:Beta:test_failure',
                       name='test_failure',
                       time=re.compile('\d+\.?\d*'),
                       children=[
                           XC(tag='failure',
                              message='failing assertion',
                              type='assertion'),
                           XC(tag='failure', message='Equal',
                              type='assertion'),
                       ],
                   ),
                   XC(tag='testcase',
                      classname='Secondary:Beta:test_error',
                      name='test_error',
                      time=re.compile('\d+\.?\d*'),
                      children=[
                          XC(tag='error',
                             message=re.compile(
                                 'Traceback(.|\s)+Exception:\sfoo'))
                      ]),
               ])
        ])

    test_ctx = ((xml_primary, xml_primary_comparison),
                (xml_secondary, xml_secondary_comparison))

    for file_path, xml_comparison in test_ctx:
        with open(file_path) as xml_file:
            xml_comparison.compare(xml_file.read())