Coder Social home page Coder Social logo

Comments (22)

hasanibnmansoor avatar hasanibnmansoor commented on August 18, 2024 2

@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

from htmltestrunner.

bobwassell avatar bobwassell commented on August 18, 2024 1

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

from htmltestrunner.

tungwaiyip avatar tungwaiyip commented on August 18, 2024

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.

alain1 avatar alain1 commented on August 18, 2024

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

from htmltestrunner.

tungwaiyip avatar tungwaiyip commented on August 18, 2024

No it have not been updated in a long time.

from htmltestrunner.

kaphola avatar kaphola commented on August 18, 2024

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.

SulakshnaDas avatar SulakshnaDas commented on August 18, 2024

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.

tungwaiyip avatar tungwaiyip commented on August 18, 2024

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.

ElaineAng avatar ElaineAng commented on August 18, 2024

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.

SulakshnaDas avatar SulakshnaDas commented on August 18, 2024

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

ElaineAng avatar ElaineAng commented on August 18, 2024

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

locus2k avatar locus2k commented on August 18, 2024

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.

maulikthaker avatar maulikthaker commented on August 18, 2024

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.

KarimMorkos avatar KarimMorkos commented on August 18, 2024

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">

from htmltestrunner.

dash0002 avatar dash0002 commented on August 18, 2024

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

from htmltestrunner.

dheerajalim avatar dheerajalim commented on August 18, 2024

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

from htmltestrunner.

Akopov4 avatar Akopov4 commented on August 18, 2024

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.

dash0002 avatar dash0002 commented on August 18, 2024

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.

dheerajalim avatar dheerajalim commented on August 18, 2024

from htmltestrunner.

Akopov4 avatar Akopov4 commented on August 18, 2024

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

from htmltestrunner.

dash0002 avatar dash0002 commented on August 18, 2024

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

tjtripp avatar tjtripp commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.