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

Is it Python 3.2 Compatible ? #1

Open
nuummi opened this issue Mar 31, 2011 · 22 comments
Open

Is it Python 3.2 Compatible ? #1

nuummi opened this issue Mar 31, 2011 · 22 comments
Labels

Comments

@nuummi
Copy link

nuummi commented Mar 31, 2011

Hello Wai Yip,
I'm using your module and it's working great!!
Recently I was trying to use an earlier version of HTMLTestRunner in Python 3.2, but it could not run. Is the new version (0.8.2) compatible for Python 3.2 ?

Thanks!
Noam.

@tungwaiyip
Copy link
Owner

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.

@alain1
Copy link

alain1 commented Aug 11, 2014

hi
has this been updated to run with the latest version of python?

@tungwaiyip
Copy link
Owner

No it have not been updated in a long time.

@kaphola
Copy link

kaphola commented Sep 15, 2014

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

@SulakshnaDas
Copy link

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

@tungwaiyip
Copy link
Owner

I'm not able to spend any time on this project. If anyone can kindly continue the development it will be much appreciated.

@ElaineAng
Copy link

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!

@SulakshnaDas
Copy link

@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

@ElaineAng
Copy link

@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...

@locus2k
Copy link

locus2k commented Sep 28, 2015

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)

@maulikthaker
Copy link

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:

@KarimMorkos
Copy link

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"?>
<title>%(title)s</title> %(stylesheet)s <script language="javascript" type="text/javascript">

@dash0002
Copy link

dash0002 commented May 19, 2016

You may want to use the fork available at https://github.com/dash0002/HTMLTestRunner which is ready for Python 3.

@dheerajalim
Copy link

dheerajalim commented Jan 7, 2017

You can use the fork https://github.com/dheerajalim/HTMLTestRunner
This is compatible with Python 3 - 3.5.1

@Akopov4
Copy link

Akopov4 commented Mar 19, 2017

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'

@dash0002
Copy link

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?

@dheerajalim
Copy link

dheerajalim commented Mar 20, 2017 via email

@Akopov4
Copy link

Akopov4 commented Mar 20, 2017

@dash0002 yes it appears in 3.5.2. @dheerajalim unclear- please explain

@hasanibnmansoor
Copy link

hasanibnmansoor commented Apr 7, 2017

@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:

  1. import StringIO to import io as StringIO
  2. Change the print statement in Line 630 to print('Time Elapsed: {}'.format((self.stopTime-self.startTime)), file=sys.stderr)
  3. Change the if not rmap.has_key(cls) in Line 642 to if cls not in rmap:
  4. 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")
  5. 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

@dash0002
Copy link

@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).

@tjtripp
Copy link

tjtripp commented Apr 24, 2017

I've just confirmed that this package works: https://github.com/oldani/HtmlTestRunner
Just download the .whl file from PyPI and install from console.

@bobwassell
Copy link

This works well.
https://programming.vip/docs/python-3.x-install-htmltestrunner-and-use.html
tested in 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests