Comments (22)
@Akopov4 I tried this and it worked.
outfile = open(dir + "\SmokeTestReport.html", "wb")
In code to open the file, give 'wb' instead of 'w' and it should work. It worked for me.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Summarizing the changes, following changes to the original HTMLTestRunner file would get things work:
- import StringIO to import io as StringIO
- Change the print statement in Line 630 to print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr)
- Change the if not rmap.has_key(cls) in Line 642 to if cls not in rmap:
- In the Python Code to Open the File (Your testing code, not HTMLTestRunner.py), update the code to open the report file to have "wb" instead of "w"
# open the report file
outfile = open(dir + "\SmokeTestReport.html", "wb") - Change the decoding statement in line 766 and 772 to uo = bytes(o, 'utf-8').decode('latin-1') and ue = bytes(e, 'utf-8').decode('latin-1') respectively.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Above steps got me working in Python 3.6
from htmltestrunner.
This works well.
https://programming.vip/docs/python-3.x-install-htmltestrunner-and-use.html
tested in 3.9
from htmltestrunner.
Good question. HTMLTestRunner date back to 2005 and has not been ported to Python 3. This is an excellent request to work on. Unicode handling was a mess back in the old days (Python 2.4?). I am looking forward for easier time in Python 3.
from htmltestrunner.
hi
has this been updated to run with the latest version of python?
from htmltestrunner.
No it have not been updated in a long time.
from htmltestrunner.
Hi Wai,
I was using your module HTMLTestRunner.py for generating report with selenium 2.35.0 and python 2.7 and it was working fine.
Now i upgraded python 2 to python 3 and selenium 2.35.0 to selenium 2.43.0, now i am able to run my test cases but it is not generating report.
Kindly let me know have you added support for python 3.
Thanks,
Ajay
from htmltestrunner.
Hi Wai,
I am using HTMLTestRunner.py for generating report with python2.6 and it is working fine but now I am upgrading python 2.6 to python 3.4.So Do you have any update on HTMLTestRunner compatible to python 3.4?
Thanks,
Sulakshna
from htmltestrunner.
I'm not able to spend any time on this project. If anyone can kindly continue the development it will be much appreciated.
from htmltestrunner.
I made some small changes to your project and it now works for me (with python 3.4), although probably the changes are not decent enough.
Thank you so much for your work!
from htmltestrunner.
@ElaineAng Could you please tell me about changes that you made in this module which worked for you.It would be of great help to me.
Thanks,
Sulakshna
from htmltestrunner.
@SulakshnaDas Hi, sorry for the late reply. I am a beginner on python so I don't know whether the changes I made is decent. I was using code from his website, which seems to have slight (and unimportant) difference from the code in the github here. website URL: http://tungwaiyip.info/software/HTMLTestRunner_0_8_2/HTMLTestRunner.py
The changes that I made:
Line 94: from io import *
Line 538, in method startTest(self,test): self.outputBuffer=StringIO()
Line 631, in method run(self,test): print ("\nTime Elapsed: %s" %(self.stopTime-self.startTime),
file=sys.stderr)
In method _generate_report_test(self,rows,cid,tid,n,t,o,e):
Line 766: uo=o
Line 768: uo=o.decode()
Line 772: ue=e
Line 774: ue=e.decode()
Hopefully it helps...
from htmltestrunner.
In 3.x it is no longer StringIO.
Here are the changes that I made to get it to work for 3.4
Line 94: import io as StringIO
Line 63: print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr)
in the methoid __generate_report_test: change all the decodes to: uo = bytes(o, 'utf-8').decode('latin-1') (or ue and e)
from htmltestrunner.
Correction from above : Itls line 632.
Insert this in line 692 : self.stream.write(output)
Insert this in line 644 : if not cls in rmap.keys:
from htmltestrunner.
to work with 3.x
"""
A TestRunner for use with the Python unit testing framework. It
generates a HTML report to show the result at a glance.
The simplest way to use this is to invoke its main method. E.g.
import unittest
import HTMLTestRunner
... define your tests ...
if __name__ == '__main__':
HTMLTestRunner.main()
For more customization options, instantiates a HTMLTestRunner object.
HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g.
# output to a file
fp = file('my_report.html', 'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title='My unit test',
description='This demonstrates the report output by HTMLTestRunner.'
)
# Use an external stylesheet.
# See the Template_mixin class for more customizable options
runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">'
# run the test
runner.run(my_test_suite)
Copyright (c) 2004-2007, Wai Yip Tung
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. - Neither the name Wai Yip Tung nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
URL: http://tungwaiyip.info/software/HTMLTestRunner.html
author = "Wai Yip Tung"
version = "0.8.2"
"""
Change History
Version 0.8.2
- Show output inline instead of popup window (Viorel Lupu).
Version in 0.8.1
- Validated XHTML (Wolfgang Borgert).
- Added description of test classes and test cases.
Version in 0.8.0
- Define Template_mixin class for customization.
- Workaround a IE 6 bug that it does not treat <script> block as CDATA.
Version in 0.7.1
- Back port to Python 2.3 (Frank Horowitz).
- Fix missing scroll bars in detail log (Podi).
"""
TODO: color stderr
TODO: simplify javascript using ,ore than 1 class in the class attribute?
import datetime
import sys
import time
import unittest
from xml.sax import saxutils
from io import StringIO
------------------------------------------------------------------------
The redirectors below are used to capture output during testing. Output
sent to sys.stdout and sys.stderr are automatically captured. However
in some cases sys.stdout is already cached before HTMLTestRunner is
invoked (e.g. calling logging.basicConfig). In order to capture those
output, use the redirectors for the cached stream.
e.g.
>>> logging.basicConfig(stream=HTMLTestRunner.stdout_redirector)
>>>
class OutputRedirector(object):
""" Wrapper to redirect stdout or stderr """
def init(self, fp):
self.fp = fp
def write(self, s):
self.fp.write(s)
def writelines(self, lines):
self.fp.writelines(lines)
def flush(self):
self.fp.flush()
stdout_redirector = OutputRedirector(sys.stdout)
stderr_redirector = OutputRedirector(sys.stderr)
----------------------------------------------------------------------
Template
class Template_mixin(object):
"""
Define a HTML template for report customerization and generation.
Overall structure of an HTML report
HTML
+------------------------+
|<html> |
| <head> |
| |
| STYLESHEET |
| +----------------+ |
| | | |
| +----------------+ |
| |
| </head> |
| |
| <body> |
| |
| HEADING |
| +----------------+ |
| | | |
| +----------------+ |
| |
| REPORT |
| +----------------+ |
| | | |
| +----------------+ |
| |
| ENDING |
| +----------------+ |
| | | |
| +----------------+ |
| |
| </body> |
|</html> |
+------------------------+
"""
STATUS = {
0: 'pass',
1: 'fail',
2: 'error',
}
DEFAULT_TITLE = 'Unit Test Report'
DEFAULT_DESCRIPTION = ''
# ------------------------------------------------------------------------
# HTML Template
HTML_TMPL = r"""<?xml version="1.0" encoding="UTF-8"?>
from htmltestrunner.
You may want to use the fork available at https://github.com/dash0002/HTMLTestRunner which is ready for Python 3.
from htmltestrunner.
You can use the fork https://github.com/dheerajalim/HTMLTestRunner
This is compatible with Python 3 - 3.5.1
from htmltestrunner.
hI, none of these solutions work with python 3.5.2 . If I used solution of @dheerajalim I have got such errors:
File "/home/akop/py_workspace/setest/2/smoketests_with_html_report.py", line 26, in <module>
runner.run(smoke_tests)
File "/home/akop/py_workspace/setest/2/HTMLTestRunner.py", line 562, in run
self.generateReport(test, result)
File "/home/akop/py_workspace/setest/2/HTMLTestRunner.py", line 619, in generateReport
self.stream.write(output.encode('utf8'))
TypeError: write() argument must be str, not bytes
If I used solution of @dash0002 I got such errors:
/usr/bin/python3.5 /home/akop/py_workspace/setest/2/smoketests_with_html_report.py
.....Traceback (most recent call last):
File "/home/akop/py_workspace/setest/2/smoketests_with_html_report.py", line 26, in <module>
runner.run(smoke_tests)
File "/home/akop/py_workspace/setest/2/HTMLTestRunner.py", line 538, in run
self.generateReport(test, result)
File "/home/akop/py_workspace/setest/2/HTMLTestRunner.py", line 586, in generateReport
report = self._generate_report(result)
File "/home/akop/py_workspace/setest/2/HTMLTestRunner.py", line 646, in _generate_report
cid = 'c%s' % (cid+1),
KeyError: 'skip'
from htmltestrunner.
Quick double check @Akopov4; With the version available from @dheerajalim or @dash0002 it works in 3.5.1, but in 3.5.2 you receive this error?
from htmltestrunner.
from htmltestrunner.
@dash0002 yes it appears in 3.5.2. @dheerajalim unclear- please explain
from htmltestrunner.
@Akopov4 I'd be very happy to accept a pull request for this change at https://github.com/dash0002/HTMLTestRunner (which should be 3 compatible branch).
from htmltestrunner.
I've just confirmed that this package works: https://github.com/oldani/HtmlTestRunner
Just download the .whl file from PyPI and install from console.
from htmltestrunner.
Related Issues (14)
- It does not work with Python 3 HOT 4
- Why is the redirection of the stderr and stdout output nessary ?
- HTML报告中新增一列,存放错误截图
- Text of test result is exceeding the cell margin HOT 2
- HTMLTestRunner.py has a bug
- 'No module named 'HTMLTestRunner' HOT 4
- selenium 2.45, Pythhon 3.6.2 with HTMLTestRunner
- why was the file where I want to write a test_report into alway closed
- Unable to import HtmlTestRunner ModuleNotFoundError: No module named 'HtmlTestRunner'
- expand collapse button for traceback in error log window HOT 5
- Storing HtmlTestRunner reports in Web Server HOT 3
- HTMLTestRunner runs more than once HOT 1
- Detail output overlap HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from htmltestrunner.