Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failure tag for failed testcase, and changes on testcase's name #2

Open
wants to merge 7 commits into
base: publish
Choose a base branch
from
36 changes: 29 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,55 @@ def create_testsuites():

return (testsuites, testsuite)

def add_failure(prefix, testcase, request_method, request_name):
failure = ET.SubElement(testcase, 'failure')
csv_file_path = os.path.join(os.getcwd(), prefix + '_failures.csv')
failure_message = ''

with open(csv_file_path, mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)

for row in csv_reader:
row_method = row['Method']
row_name = row['Name']

if row_method == request_method and row_name == request_name:
failure_message = row['Error']
break

failure.set('message', failure_message)


def append_testcases(prefix, testsuite):
test_count = 0
failure_count = 0
testsuite_failure_count = 0
csv_file_path = os.path.join(os.getcwd(), prefix + '_stats.csv')

with open(csv_file_path, mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)

for row in csv_reader:

row_method = row['Type']
row_name = row['Name']

if row_method != '' and row_method != 'None' and row_name != 'Total':
testcase = ET.SubElement(testsuite, 'testcase')

name = f'{row_method}\t{row_name} Average response time'
name = f'{row_method}: {row_name}'
testcase.set('name', name)

test_count += int(row['Request Count'])
failure_count += int(row['Failure Count'])
testcase.set('tests', str(test_count))
testcase_failure_count = int(row['Failure Count'])
testsuite_failure_count += testcase_failure_count
testcase.set('failures', str(testcase_failure_count))

if testcase_failure_count > 0:
add_failure(prefix, testcase, row_method, row_name)

avg_response_s = float(row['Average Response Time']) / 1000
testcase.set('time', str(avg_response_s))

testsuite.set('tests', str(test_count))
testsuite.set('failures', str(failure_count))
testsuite.set('failures', str(testsuite_failure_count))


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def assert_file(self, prefix: str, test_case_names: list[str]) -> None:

def test_conversion(self):
self.assert_file('prefix1', [
'GET\t/ Average response time',
'GET\t/fail Average response time',
'GET: /',
'GET: /fail',
])

self.assert_file('prefix2', [
'GET\t/ Average response time',
'GET\t/fail Average response time',
'GET: /',
'GET: /fail',
])
return

Expand Down