473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding further report options to unittest.py

Hi all.

I would like to change the way test reports are generated, in a Zope
environment.

I'm playing with TextTestReport, TextTestRunner. Since things are
getting to complicated, I'm afraid I'm following a non-pythonic way.

Specifically, I would like to have an output like:

package.subpackage.test_module.TestCase 0.1

where 0.1 is the time spent into doing the test.

In a previous attempt, I made the tests print the number of the test
executed, so that I would have the following output:

1 package.subpackage.test_module.TestCase

however, to do this, I had to put things in the following way:
class PAFlowTestRunner(TextTestRunner):
def _makeResult(self):
return PAFlowTextResult(self.stream, self.descriptions, self.verbosity)

class PAFlowTextResult(_TextTestResult):

def startTest(self, test):
self.stream.write("%s " % self.testsRun)
_TextTestResult.startTest(self, test)
now, of course, this is ugly, because I'm using _TextTestResult, which
I'm not supposed to know, and I'm changing behaviour by subclassing,
which is not exactly what I would like to do.

What is the pythonic way to accomplish this?

Marco
--
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
Sep 10 '08 #1
2 1324
Marco Bizzarri wrote:
Hi all.

I would like to change the way test reports are generated, in a Zope
environment.

I'm playing with TextTestReport, TextTestRunner. Since things are
getting to complicated, I'm afraid I'm following a non-pythonic way.

Specifically, I would like to have an output like:

package.subpackage.test_module.TestCase 0.1

where 0.1 is the time spent into doing the test.

In a previous attempt, I made the tests print the number of the test
executed, so that I would have the following output:

1 package.subpackage.test_module.TestCase

however, to do this, I had to put things in the following way:
class PAFlowTestRunner(TextTestRunner):
def _makeResult(self):
return PAFlowTextResult(self.stream, self.descriptions,
self.verbosity)

class PAFlowTextResult(_TextTestResult):

def startTest(self, test):
self.stream.write("%s " % self.testsRun)
_TextTestResult.startTest(self, test)
now, of course, this is ugly, because I'm using _TextTestResult, which
I'm not supposed to know, and I'm changing behaviour by subclassing,
which is not exactly what I would like to do.

What is the pythonic way to accomplish this?
Have you looked at nosetests? Nose is a test-discovery & running-framework
based upon unittest-module (but you can also "only" test simple functions,
very handy)

And it has a very powerful plugin-mechanism, that allows you to implement
cleanly what you want.

For each test, you get a start/end-method called in your plugin that you can
use to gather the information you need, e.g. start/stop-times.

For example, I've created an enhanced reporting plugin that lists all tests
run (not only those failed or error'ed), and adding time-measuring per-test
is on my list of todos.

Diez
Sep 10 '08 #2
On Wed, Sep 10, 2008 at 3:25 PM, Diez B. Roggisch <de***@nospam.web.dewrote:
Marco Bizzarri wrote:
>Hi all.

I would like to change the way test reports are generated, in a Zope
environment.

Have you looked at nosetests? Nose is a test-discovery & running-framework
based upon unittest-module (but you can also "only" test simple functions,
very handy)
Nope; next time I will make a google search before posting ;)
And it has a very powerful plugin-mechanism, that allows you to implement
cleanly what you want.

For each test, you get a start/end-method called in your plugin that you can
use to gather the information you need, e.g. start/stop-times.

I gave it a look; it is nice and it seems powerful; I just wonder if I
need to put my hands on all my tests to do what I want to do... but
I'm sure this can be sorted in the documentation.

For example, I've created an enhanced reporting plugin that lists all tests
run (not only those failed or error'ed), and adding time-measuring per-test
is on my list of todos.

Looks like there is a new tool I need to learn... ah, nice times when
all you needed was an hammer and a screwdriver... ;)
Thanks for the suggestion, Diez, I'll read it.

Diez

--
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/
Sep 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1491
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(),...
7
2051
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
6
3053
by: 6thirty | last post by:
Hi, I've created a stocktaking database using Access XP. This is indexed by two fields - part number and shelf location. I am currently inputting all the data via a form. When I have entered a...
3
3417
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
2
2433
by: Oleg Paraschenko | last post by:
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and...
0
2293
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler...
5
2199
by: consonanza | last post by:
I am working on a report filter form. It has 2 combo boxes (cmboSelectSubject and cmboSelectCategory) to select criteria. Selecting an entry in combo 1 restricts the options available in combo 2....
2
1319
by: chrisber | last post by:
using the unittest module in Python 2.3.5, I've written some test code that ends up with if __name__ == "__main__": unittest.main() Since I want to run this code in various environments, I'd...
3
1956
by: Paul Moore | last post by:
My normal testing consists of a tests.py script using unittest, with the basic if __name__ == '__main__': unittest.main() incantation to get things going. But I now want to incorporate...
0
6899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7067
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6847
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5312
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2980
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.