473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reliable unit test logging

Hi all!

I have many many many python unit test, which are used for testing some
remote web service.

The most important issue here is logging of test execution process and
result. I strongly need following:
1. start/end timestamp for each test case (most important)
2. immediate report about exceptions (stacktrace)
3. it will be nice to use logging module for output

I have investigated some extension for standard unittest module, e.g.
testoob, nose, etc. They have very nice features but they does not
satisfy first requirement in my list - test execution logs not doesn't
contain timestamps.

Can someone explain my why so simple feature like logging of timestamps
during test execution was not implemented in any extension?

Also i need some advices about how i can implement timestamps logging
myself. I think proper way is develop customized TextTestRunner and use
logging module instead of "print"s. Is it right way or there is more simply?

Oct 1 '07 #1
6 5686
Vyacheslav Maslov <vm*****@swsoft .comwrites:
I have many many many python unit test, which are used for testing
some remote web service.
Part of your confusion comes from the fact that "test a remote
service" isn't what a unit test does.

A unit test is one that executes a very *limited* part of the code: it
tests a code unit, not the whole system, and makes a simple set of
assertions about the result. If there are accesses to remote services
over the network, that's far beyond the scope of a unit test.

I don't doubt that you may be using the Python standard library module
'unittest' to perform these tests. But they're not unit tests; they're
integration tests, or system tests, or performance tests, or something
else.
Can someone explain my why so simple feature like logging of
timestamps during test execution was not implemented in any
extension?
Probably because the most important thing to know for the purpose of a
unit test is whether the yes/no assertions were violated. Knowing when
the tests start and finish isn't interesting. If start and finish
times *are* interesting for your tests, you're *not* doing unit
testing, but some other form of testing like performance tests.
That said, you *can* certainly instrument the unittest.TestCa se with
timings if you want to use it for a performance test. Every instance
of a TestCase will invoke its setUp method to set up test fixtures,
and its tearDown method to tear down fixtures. You can use that hook
to implement logging.

Untested code, that should give you enough to try it out yourself:

import unittest
import logging

logging.basicCo nfig(level=logg ing.INFO,
datefmt="%Y-%m-%d %H:%M:%S",
format="%(ascti me)s:%(levelnam e)s:%(message)s ")

class TimedTestCase(u nittest.TestCas e):
""" A test case that will log its start and end times """

def setUp(self):
""" Set up test fixtures """
logging.info("t est case setup")

def tearDown(self):
""" Tear down test fixtures """
logging.info("t est case teardown")

class Test_FooBar(Tim edTestCase):
""" Test cases for FooBar """

def test_slices_spa m(self):
""" FooBar should slice spam """
self.failUnless (sends_spam)

def test_eats_eggs( self):
""" FooBar should eat eggs """
self.failUnless (eats_eggs)

--
\ "The World is not dangerous because of those who do harm but |
`\ because of those who look at it without doing anything." |
_o__) —Albert Einstein |
Ben Finney
Oct 1 '07 #2
Ben Finney wrote:
Vyacheslav Maslov <vm*****@swsoft .comwrites:
>I have many many many python unit test, which are used for testing
some remote web service.

Part of your confusion comes from the fact that "test a remote
service" isn't what a unit test does.

A unit test is one that executes a very *limited* part of the code: it
tests a code unit, not the whole system, and makes a simple set of
assertions about the result. If there are accesses to remote services
over the network, that's far beyond the scope of a unit test.

I don't doubt that you may be using the Python standard library module
'unittest' to perform these tests. But they're not unit tests; they're
integration tests, or system tests, or performance tests, or something
else.
>Can someone explain my why so simple feature like logging of
timestamps during test execution was not implemented in any
extension?

Probably because the most important thing to know for the purpose of a
unit test is whether the yes/no assertions were violated. Knowing when
the tests start and finish isn't interesting. If start and finish
times *are* interesting for your tests, you're *not* doing unit
testing, but some other form of testing like performance tests.
I understand your opinion, you are right, i use unit tests for some
other kind of work. But anyway it works and produce good results for
project.
Untested code, that should give you enough to try it out yourself:
Thanks i will look into this.

Oct 2 '07 #3
Vyacheslav Maslov <vm*****@swsoft .comwrites:
I understand your opinion
Hopefully you mean "explanatio n", not "opinion". I gave what appear to
me to be facts, not opinion, about the definition of a unit test.
you are right, i use unit tests for some other kind of work.
More accurately: you use the Python 'unittest' framework for some
tests that are not unit tests.
But anyway it works and produce good results for project.
Indeed, there's nothing wrong with using the module this way. The only
trouble in this case is confused terminology, that has led you to
believe the module is deficient, when actually it's doing the job it's
meant to do.
Thanks i will look into this.
Glad to help.

--
\ "Holy uncanny photographic mental processes, Batman!" -- Robin |
`\ |
_o__) |
Ben Finney
Oct 2 '07 #4
Ben Finney wrote:
Vyacheslav Maslov <vm*****@swsoft .comwrites:
>I understand your opinion

Hopefully you mean "explanatio n", not "opinion". I gave what appear to
me to be facts, not opinion, about the definition of a unit test.
Yes, i meant "explanatio n".

I have one more question related to logging module, not unit test. I use
FileHandler to append information to file log, in fact location of log
file depends on some external factor and is calculated during
initialization. Furthermore i want to use configuration file because it
is comfortable way. So i need way to define in configuration file some
variable which should evaluated during logging system initialization, i
try following way:

[handler_hand02]
class=FileHandl er
level=NOTSET
formatter=form0 1
args=(logFileDi r+"myfile.log", "a",)
logFileDir is defined in scope of module which call
logging.config. fileConfig()

and it produces "name 'logFileDir' is not defined" exception. As i
understand this happens because inside logging module variable
logFileDir is not visible. How i can avoid this?

Thanks!

--
Oct 3 '07 #5
Vyacheslav Maslov <vm*****@swsoft .comwrites:
I have one more question related to logging module, not unit test.
Please do readers a favour, then, and start a new thread (i.e. compose
a new message, not a reply in an existing thread) for unrelated
questions.

--
\ "Philosophy is questions that may never be answered. Religion |
`\ is answers that may never be questioned." —anonymous |
_o__) |
Ben Finney
Oct 4 '07 #6
En Wed, 03 Oct 2007 11:37:57 -0300, Vyacheslav Maslov <vm*****@swsoft .com>
escribi�:
I have one more question related to logging module, not unit test. I use
FileHandler to append information to file log, in fact location of log
file depends on some external factor and is calculated during
initialization. Furthermore i want to use configuration file because it
is comfortable way. So i need way to define in configuration file some
variable which should evaluated during logging system initialization, i
try following way:

[handler_hand02]
class=FileHandl er
level=NOTSET
formatter=form0 1
args=(logFileDi r+"myfile.log", "a",)
logFileDir is defined in scope of module which call
logging.config. fileConfig()

and it produces "name 'logFileDir' is not defined" exception. As i
understand this happens because inside logging module variable
logFileDir is not visible. How i can avoid this?
logging.config uses the ConfigParser class; ConfigParser has some
interpolation mechanism.
I think this should work (but I've not tested it):

[handler_hand02]
class=FileHandl er
level=NOTSET
formatter=form0 1
args=("%(logFil eDir)s"+"myfile .log","a",)

and call it using logging.config. fileConfig({"lo gFileDir":
"your/desired/path"})

--
Gabriel Genellina

Oct 7 '07 #7

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

Similar topics

14
2750
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
15
6955
by: Enrique | last post by:
Question I am posting this question again (3rd time) because some issues with my no spam alias. Here it is the question: I have not been able to run unit tests for a VSTO (2005) project. I have an Excel project and a unit test project in the same solution. I have not found the way to initialize the runtimecallback as required by the code generated
72
5264
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
5
6527
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But I can not work out a way to use it to test GUI code. Thanks a lot!
176
8405
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
1
1800
by: rich_sposato | last post by:
I released version 2.0 of C++ Unit Test Library. You can download it from SourceForget.Net at http://sourceforge.net/projects/cppunittest/ .. I wrote this unit test library because other unit test frameworks always lacked features I considered important. Some only provided output in certain formats, and I had no easy way to choose my own format. Most provided no protection against exceptions. Only a few were useful for unit-testing...
1
3444
by: Richard Lewis Haggard | last post by:
We're using VS05 and today the units tests have stopped working in our development environment. I'm sure that it is something really silly and simple but I'll be darned if I can figure out what it is. Here's a failure example: I created a simple little C# program called Test1. I added a new class that has a public method Sum, which does the brilliant function of adding two numbers together and returning the result. I added a unit test...
27
2556
by: brad | last post by:
Does anyone else feel that unittesting is too much work? Not in general, just the official unittest module for small to medium sized projects? It seems easier to write some quick methods that are used when needed rather than building a program with integrated unittesting. I see the value of it (the official unittest that is)... especially when there's a lot of source code. But this... if len(x) != y: sys.exit('...')
5
2246
by: Ben Finney | last post by:
Howdy all, PEP 299 <URL:http://www.python.org/dev/peps/pep-0299details an enhancement for entry points to Python programs: a module attribute (named '__main__') that will be automatically called if the module is run as a program. The PEP has status "Rejected", citing backward-compatibility issues, and Guido's pronouncement that "It's not worth the change (in docs, user habits, etc.) and there's nothing particularly broken."
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6750
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2193
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.