-
-
Notifications
You must be signed in to change notification settings - Fork 409
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
Conversation
abd4b6d
to
fce0b56
Compare
""" | ||
super(DokuReport, self).pytest_sessionstart(session) | ||
|
||
def pytest_runtest_logreport(self, report): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
c3d3f1a
to
2ab56ba
Compare
@@ -10,6 +10,7 @@ show-response = 1 | |||
[pytest] | |||
minversion = 2.2 | |||
norecursedirs = build docs/_build | |||
addopts = -p no:html |
There was a problem hiding this comment.
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?
- 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.
@@ -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: |
There was a problem hiding this comment.
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
- 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
except (gaierror, TypeError): | ||
uploaded_report = "" | ||
|
||
if len(uploaded_report) > 0: | ||
terminalreporter.write_sep( | ||
"-", "Successfully uploaded report to Dokuwiki") |
There was a problem hiding this comment.
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.
@yeganer is this mergeable? I'm happy to. |
This PR introduces a helper class named
DokuReport
which serves as a plugin for pytest. This class is subclassed frompytest-html.plugin.HTMLReport
class. It handles logging of test execution and upload it to Dokuwiki. It is registered as a plugin byconfig.pluginmanager
inpytest_configure
hook and unregistered inpytest_unconfigure
. Prior to this,pytest-html
plugin was used for report generation - to forcepytest
useDokuReport
instead ofHTMLReport
,pytest-html
has o be unregistered as a plugin duringpytest_configure
execution.Checklist maintains the work done so far / work TO-DO in
DokuReport
: