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

Subclass pytest-html's HTMLReport to DokuReport class for report generation and upload. #583

Merged
merged 12 commits into from
Jun 14, 2016
22 changes: 18 additions & 4 deletions tardis/tests/tests_slow/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def __init__(self, dokuwiki_details):
password=dokuwiki_details["password"])
except gaierror, dokuwiki.DokuWikiError:
self.doku_conn = None
print "Dokuwiki connection could not be established!"
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the if/else and add an except for the case dokuwiki=none

self.doku_conn = None

# This variable will be set True when report gets uploaded on Dokuwiki.
self.is_report_uploaded = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use a variable but check in sessionfinish that the page is indeed accessible.


def _generate_report(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagined _generate_report to return a string. This string would then be passed to _save_report.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay we'll do it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now you can copy/paste the code from pytest-html and note somewhere that it's copy/paste
obviously you need to split it into generate and 'save'

suite_stop_time = time.time()
suite_time_delta = suite_stop_time - self.suite_start_time
Expand Down Expand Up @@ -110,12 +112,24 @@ def _save_report(self):
self.logfile.seek(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add contents to the arguments and just add the string to the dokuwiki page


if self.doku_conn is not None:
self.doku_conn.pages.set("reports:{0}".format(
tardis.__githash__[:7]), self.logfile.read())
print "Uploaded report on Dokuwiki."
try:
self.doku_conn.pages.set("reports:{0}".format(
tardis.__githash__[:7]), self.logfile.read())
except gaierror:
self.is_report_uploaded = False
else:
self.is_report_uploaded = True

self.logfile.close()

def pytest_sessionfinish(self, session):
self._generate_report()
self._save_report()

def pytest_terminal_summary(self, terminalreporter):
if self.is_report_uploaded:
terminalreporter.write_sep(
"-", "Successfully uploaded report to Dokuwiki")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you could add the URL, too.

else:
terminalreporter.write_sep(
"-", "Connection not established, upload failed.")