Coder Social home page Coder Social logo

pycontribs / xmlrunner Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xmlrunner/unittest-xml-reporting

2.0 6.0 9.0 422 KB

unittest-based test runner with Ant/JUnit like XML reporting.

License: GNU Lesser General Public License v3.0

Makefile 3.96% Shell 6.45% Python 89.59%

xmlrunner's Introduction

unittest-xml-reporting

unittest-xml-reporting is a unittest test runner that can save test results to XML files that can be consumed by a wide range of tools, such as build systems, IDEs and continuous integration servers.

If you find a bug the best way to have it fixed is to fix it yourself and to make a pull request.

If you want you can even get direct access to the repository, is always better to have more than one maintainer.

Requirements

  • Python 2.7+

Installation

The easiest way to install unittest-xml-reporting is via Pip:

$ pip install unittest-xml-reporting

If you use Git and want to get the latest development version:

$ git clone git://github.com/danielfm/unittest-xml-reporting.git
$ cd unittest-xml-reporting
$ sudo python setup.py install

Or get the latest development version as a tarball:

$ wget http://github.com/danielfm/unittest-xml-reporting/tarball/master
$ tar zxf danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX.tar.gz
$ cd danielfm-unittest-xml-reporting-XXXXXXXXXXXXXXXX
$ sudo python setup.py install

Usage

The script below, adapted from the unittest, shows how to use XMLTestRunner in a very simple way. In fact, the only difference between this script and the original one is the last line:

import random
import unittest
import xmlrunner

class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.seq = list(range(10))

    @unittest.skip("demonstrating skipping")
    def test_skipped(self):
        self.fail("shouldn't happen")

    def test_shuffle(self):
        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, list(range(10)))

        # should raise an exception for an immutable sequence
        self.assertRaises(TypeError, random.shuffle, (1,2,3))

    def test_choice(self):
        element = random.choice(self.seq)
        self.assertTrue(element in self.seq)

    def test_sample(self):
        with self.assertRaises(ValueError):
            random.sample(self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assertTrue(element in self.seq)

if __name__ == '__main__':
    unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))

Django

In order to plug XMLTestRunner to a Django project, add the following to your settings.py:

TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'

Also, the following settings are provided so you can fine tune the reports:

TEST_OUTPUT_VERBOSE (Default: 1)

Besides the XML reports generated by the test runner, a bunch of useful information is printed to the sys.stderr stream, just like the TextTestRunner does. Use this setting to choose between a verbose and a non-verbose output.

TEST_OUTPUT_DESCRIPTIONS (Default: False)

If your test methods contains docstrings, you can display such docstrings instead of display the test name (ex: module.TestCase.test_method). In order to use this feature, you have to enable verbose output by setting TEST_OUTPUT_VERBOSE = 2.

TEST_OUTPUT_DIR (Default: ".")

Tells the test runner where to put the XML reports. If the directory couldn't be found, the test runner will try to create it before generate the XML files.

xmlrunner's People

Contributors

chrisklaiber avatar danielfm avatar daspecster avatar duncm avatar lamby avatar matthewlmcclure avatar michalsvagerka avatar radicalbiscuit avatar romuald avatar s0undt3ch avatar ssbarnea avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xmlrunner's Issues

xmlrunner fails to install on Python 3.12

When I try to install xmlrunner through pip on Python 3.12 (Dockerized), I get the following error:

4.770 Collecting xmlrunner
4.781   Downloading xmlrunner-1.7.7.tar.gz (5.6 kB)
4.790   Preparing metadata (setup.py): started
5.074   Preparing metadata (setup.py): finished with status 'error'
5.093   error: subprocess-exited-with-error
5.093
5.093   × python setup.py egg_info did not run successfully.
5.093   │ exit code: 1
5.093   ╰─> [17 lines of output]
5.093       Traceback (most recent call last):
5.093         File "/tmp/pip-install-i0yuvyyb/xmlrunner_38e90a448b434bd4a1231cd932df7852/xmlrunner/xmlrunner.py", line 13, in <module>
5.093           from unittest2.runner import TextTestRunner
5.093       ModuleNotFoundError: No module named 'unittest2'
5.093
5.093       During handling of the above exception, another exception occurred:
5.093
5.093       Traceback (most recent call last):
5.093         File "<string>", line 2, in <module>
5.093         File "<pip-setuptools-caller>", line 34, in <module>
5.093         File "/tmp/pip-install-i0yuvyyb/xmlrunner_38e90a448b434bd4a1231cd932df7852/setup.py", line 6, in <module>
5.093           from xmlrunner.version import __version__
5.093         File "/tmp/pip-install-i0yuvyyb/xmlrunner_38e90a448b434bd4a1231cd932df7852/xmlrunner/__init__.py", line 3, in <module>
5.093           from .xmlrunner import XMLTestRunner
5.093         File "/tmp/pip-install-i0yuvyyb/xmlrunner_38e90a448b434bd4a1231cd932df7852/xmlrunner/xmlrunner.py", line 17, in <module>
5.093           from unittest import TestResult, _TextTestResult, TextTestRunner
5.093       ImportError: cannot import name '_TextTestResult' from 'unittest' (/usr/local/lib/python3.12/unittest/__init__.py). Did you mean: 'TextTestResult'?
5.093       [end of output]
5.093
5.093   note: This error originates from a subprocess, and is likely not a problem with pip.
5.096 error: metadata-generation-failed

The issue seems to be on this line: https://github.com/pycontribs/xmlrunner/blob/74ae6a3c2395dd103be05b8feb9838608dd5a6e8/xmlrunner/xmlrunner.py#L17C1-L18C1

Error while installing on centos 6/7 using PIP3

Running setup.py (path:/tmp/pip_build_root/xmlrunner/setup.py) egg_info for package xmlrunner
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip_build_root/xmlrunner/setup.py", line 11, in
exec(compile(open(xmlrunner_version).read(), xmlrunner_version, 'exec'))
File "/usr/lib64/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 198: ordinal not in range(128)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in
File "/tmp/pip_build_root/xmlrunner/setup.py", line 11, in
exec(compile(open(xmlrunner_version).read(), xmlrunner_version, 'exec'))
File "/usr/lib64/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 198: ordinal not in range(128)

Can print command prompt

Hi,

When I executed the test, the ouput of print functions or docstring was recorded on the xml generated file, but It should write on the console too.

Regards.

Missing support for python 3.12

when trying to import xmlrunner using python 3.12 this exception is raised:

ImportError: cannot import name '_TextTestResult' from 'unittest' (/usr/local/lib/python3.12/unittest/__init__.py). Did you mean: 'TextTestResult'?

_TextTestResult was deprecated and removed on python 3.11

[error] AttributeError ( 'javapackage' object has no attribute 'TextIOBase' )

I am running a SikuliX 2.0.5 script that uses latest Jython 2.7.2. The script fails on import xmlrunner with below error message:
[error] AttributeError ( 'javapackage' object has no attribute 'TextIOBase' )

Earlier version of Jython does not exhibit this error.

Does xmlrunner support latest Jython 2.7.2 ?

open for maintainers!

If anyone wants to takeover maintenance of this project please add yourself here. I no longer have the time and interest for it and I will be glad to allow someone to takeover.

Crashing with UnicodeEncodeError when exceptions have special characters

crashes when some test fails with message that contains special characters:

this is where it crashes... instead of showing the error it shows the stacktrace of the xmlrunner:

======================================================================
ERROR [135.328s]: test_FEAT_PWD_CPLX_007_allSpecialChars_2 (feature_PasswordComplexity.feature_PasswordComplexity)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "runTestList.py", line 28, in <module>
    xmlrunner.XMLTestRunner(verbosity=2, output="../test-reports", stream=sys.stdout).run(suite)
  File "/home/automation_tests_pyenv/lib/python2.7/site-packages/xmlrunner/xmlrunner.py", line 421, in run
    result.printErrors()
  File "/home/automation_tests_pyenv/lib/python2.7/site-packages/unittest2/runner.py", line 116, in printErrors
    self.printErrorList('ERROR', self.errors)
  File "/home/automation_tests_pyenv/lib/python2.7/site-packages/xmlrunner/xmlrunner.py", line 221, in printErrorList
    self.stream.writeln('%s' % test_info.get_error_info())
  File "/home/automation_tests_pyenv/lib/python2.7/site-packages/unittest2/runner.py", line 32, in writeln
    self.write(arg)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 251: ordinal not in range(128)

Setup:

$uname -a
Linux servername 2.6.32-431.17.1.el6.x86_64 #1 SMP Wed May 7 23:32:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$pip list
unittest-xml-reporting (1.14.0)
unittest2 (1.1.0)
xmlrunner (1.7.7)
$echo $LANG
en_GB.UTF-8

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

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.