def test_convert_to_nunit_results_format_multiple_results_nunit(mocker): x = '{"tags": {"opId": "ServerBackend-f421e441fa310430","browserUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","orgId": "1009391617598028","userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36","clusterId": "0216-124733-lone970","user": "******","principalIdpObjectId": "71b45910-e7b4-44d8-82f7-bf6fac4630d0","browserHostName": "uksouth.azuredatabricks.net","parentOpId": "RPCClient-bb9b9591c29c01f7","jettyRpcType": "InternalDriverBackendMessages$DriverBackendRequest"},"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}' context = json.loads(x) mocker.patch("runeatest.pysparkconnect.get_context", return_value=context) t = ("2020-9-13", "13:20:16") mocker.patch("runeatest.utils.get_date_and_time", return_value=t) results = [] results.append(testreporter.add_testcase("test name 3", True)) results.append(testreporter.add_testcase("test name 4", True)) results2 = [] results2.append(testreporter.add_testcase("test name 5", True)) results2.append(testreporter.add_testcase("test name 6", True)) context = pysparkconnect.get_context() header = nunitresults.get_nunit_header(results, context) suite = nunitresults.get_test_suite_results(results, context) test_cases = nunitresults.get_test_case_results(results) test_cases += nunitresults.get_test_case_results(results) footer = nunitresults.get_nunit_footer() str_test_cases = "\n".join(test_cases) actual = header + "\n" + suite + "\n" + str_test_cases + "\n" + footer now = datetime.now() now_date = str(now.year) + str(now.month) + str(now.day) now_time = (str(now.hour) + str(now.minute) + str(now.second) + str(now.second) + str(now.microsecond)) fname = "{thisdate}_{thistime}_nunit_test_results.xml".format( thisdate=now_date, thistime=now_time) f = open(fname, "w") f.write(actual) f.close()
def test_get_test_suite_result_one_failed(mocker): x = '{"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}' context = json.loads(x) mocker.patch("runeatest.pysparkconnect.get_context", return_value=context) results = [] results.append(testreporter.add_testcase("test name", False)) expected = '<test-suite type="TestFixture" name="/Users/[email protected]/runeatest" executed="True" result="failure" success="False" time="0.000" asserts="0"><results>' actual = nunitresults.get_test_suite_results(results, context) assert expected == actual
def test_get_test_suite_result_all_passed(mocker): x = '{"extraContext":{"notebook_path":"/Users/[email protected]/runeatest"}}' context = json.loads(x) mocker.patch("runeatest.pysparkconnect.get_context", return_value=context) results = [] results.append( testreporter.add_testcase( "test name", True, "test may also have failed but because it did not this is not included in output", )) results.append( testreporter.add_testcase( "test name 2", True, "test may have failed but because it did not this is not included in output", )) expected = '<test-suite type="TestFixture" name="/Users/[email protected]/runeatest" executed="True" result="success" success="True" time="0.000" asserts="0"><results>' actual = nunitresults.get_test_suite_results(results, context) assert expected == actual