def plan(tmpdir): """Yield an interactive testplan.""" plan = testplan.TestplanMock( name=six.ensure_str("InteractiveAPITest"), interactive_port=0, interactive_block=False, exporters=[XMLExporter(xml_dir=tmpdir / "xml_exporter")], ) logfile = tmpdir / "attached_log.txt" logfile.write_text( "This text will be written into the attached file.", encoding="utf8", ) plan.add( multitest.MultiTest( name=six.ensure_str("ExampleMTest"), suites=[ExampleSuite(str(logfile))], ) ) plan.run() timing.wait( lambda: plan.interactive.http_handler_info is not None, 300, raise_on_timeout=True, ) yield plan plan.abort()
def plan(tmpdir): """Yield an interactive testplan.""" with mock.patch("testplan.runnable.interactive.reloader.ModuleReloader" ) as MockReloader: MockReloader.return_value = None plan = testplan.TestplanMock( name="InteractiveAPITest", interactive_port=0, interactive_block=False, exporters=[XMLExporter(xml_dir=str(tmpdir / "xml_exporter"))], ) logfile = tmpdir / "attached_log.txt" logfile.write_text( "This text will be written into the attached file.", encoding="utf-8", ) plan.add( multitest.MultiTest( name="ExampleMTest", suites=[ExampleSuite(str(logfile))], )) plan.run() timing.wait( lambda: plan.interactive.http_handler_info is not None, 300, raise_on_timeout=True, ) yield plan plan.abort()
def test_xml_exporter_cleanup(tmpdir): """ XMLExporter should purge & recreate XML dir """ xml_dir = tmpdir.mkdir("xml") assert os.listdir(xml_dir.strpath) == [] open(xml_dir.join("foo.txt").strpath, "a").close() XMLExporter(xml_dir=xml_dir.strpath).export(sample_report) assert os.listdir(xml_dir.strpath) == ["my-multitest.xml"]
def test_xml_exporter_cleanup(tmpdir): """ XMLExporter should purge & recreate XML dir """ xml_dir = tmpdir.mkdir('xml') assert os.listdir(xml_dir.strpath) == [] open(xml_dir.join('foo.txt').strpath, 'a').close() with log_propagation_disabled(TESTPLAN_LOGGER): XMLExporter(xml_dir=xml_dir.strpath).export(sample_report) assert os.listdir(xml_dir.strpath) == ['my-multitest.xml']
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())
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())
def __call__(self, result: TestReport) -> TestReport: exporter = XMLExporter(xml_dir=self.dir_name) exporter.export(result) self.logger.test_info(f"XML files written to {self.dir_name}") return result