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

Conversation

kdexd
Copy link

@kdexd kdexd commented Jun 7, 2016

This PR introduces a helper class named DokuReport which serves as a plugin for pytest. This class is subclassed from pytest-html.plugin.HTMLReport class. It handles logging of test execution and upload it to Dokuwiki. It is registered as a plugin by config.pluginmanager in pytest_configure hook and unregistered in pytest_unconfigure. Prior to this, pytest-html plugin was used for report generation - to force pytest use DokuReport instead of HTMLReport, pytest-html has o be unregistered as a plugin during pytest_configure execution.

Checklist maintains the work done so far / work TO-DO in DokuReport:

  • Include summary and execution duration, generation time and commit hash.
  • Include test name, duration, result.
  • Embed plots, and error logs if any.
  • Handle dokuwiki connection and interaction from within the class.
  • Handle tempfile writing from within the class.
  • Make sure that this plugin is not activated when integration tests are not selected.

@kdexd kdexd force-pushed the dokureport-class branch 3 times, most recently from abd4b6d to fce0b56 Compare June 8, 2016 05:26
"""
super(DokuReport, self).pytest_sessionstart(session)

def pytest_runtest_logreport(self, report):
Copy link
Member

Choose a reason for hiding this comment

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

why are these functions here?

Copy link
Author

Choose a reason for hiding this comment

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

These are pytest hooks, this class is registered as a plugin so pytest automatically calls these hook functions. I'll update this PR by their removal if removing them also works (it should, according to inheritance).

@kdexd kdexd force-pushed the dokureport-class branch 2 times, most recently from c3d3f1a to 2ab56ba Compare June 9, 2016 06:49
@@ -10,6 +10,7 @@ show-response = 1
[pytest]
minversion = 2.2
norecursedirs = build docs/_build
addopts = -p no:html
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this?

Karan Desai added 6 commits June 9, 2016 13:05
- Added pytest-html in requirements as a dependency.
- This tempfile will get deleted upon closing and
  no longer needs os.unlink while execution of
  pytest_nconfigure hook.
- Override base class' pytest_terminal_summary method
  and display message according to success / failure
  of upload of report.

- Try/ except methods are introduced wherever there is
  an attempt to interact with dokuwiki is made.
@kdexd kdexd force-pushed the dokureport-class branch from 2ab56ba to a392364 Compare June 9, 2016 07:38
@@ -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

Karan Desai added 2 commits June 9, 2016 16:23
- tempfile is no longer used to write the report and upload
  it to dokuwiki.

- _generate_report returns a string which is accepted by
  _save_report to upload it on Dokuwiki.
- Instead of doing 'if dokuwiki is not None', a try-except
  block is used to catch a 'TypeError'.
try:
import dokuwiki
except ImportError:
dokuwiki = None
Copy link
Member

Choose a reason for hiding this comment

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

why not dokuwiki_available = False

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no reason to have the dokuwiki_available variable. Since we are
ductyping anyway we can catch the case dokuwiki == None in the same block.

Wolfgang Kerzendorf [email protected] schrieb am Do., 9. Juni 2016
um 13:50 Uhr:

In tardis/tests/tests_slow/report.py
#583 (comment):

+import datetime
+import pkg_resources
+import os
+import time
+
+# For specifying error while exception handling
+from socket import gaierror
+
+from py.xml import html, raw
+from pytest_html.plugin import HTMLReport
+import tardis
+
+try:

  • import dokuwiki
    +except ImportError:
  • dokuwiki = None

why not dokuwiki_available = False


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/tardis-sn/tardis/pull/583/files/39748519f55d18998f52984f9929bfc1876a2782#r66426452,
or mute the thread
https://github.com/notifications/unsubscribe/AF4OjvHknV68nNtK4Rc7R-9fGlF0-7Mzks5qJ_4TgaJpZM4Iv3C8
.

Copy link
Member

Choose a reason for hiding this comment

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

I think that makes for convoluted code, where it is not clear why it is excepting. But I withdraw my comment for now.

- Report content is requested from dokuwiki using pages.get
  method and report upload is said to be successful if a non
  empty string is received.
@kdexd kdexd changed the title Create standalone DokuReport class for report generation and upload. Subclass pytest-html's HTMLReport to DokuReport class for report generation and upload. Jun 9, 2016
except (gaierror, TypeError):
uploaded_report = ""

if len(uploaded_report) > 0:
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.

@wkerzendorf
Copy link
Member

@yeganer is this mergeable? I'm happy to.

@yeganer yeganer merged commit 3f14163 into tardis-sn:master Jun 14, 2016
@kdexd kdexd deleted the dokureport-class branch June 22, 2016 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants