473,974 Members | 7,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using other tools with unittest?

Has anyone used tools like pychecker (or even Python's own debugger or
profiler) during unit testing? Here are some things that might be natural
to do:

1. pychecker can run all kinds of fancy tests on code. I'm wondering
whether these tests could be incorporated somehow into individual unit
tests. For example, one might use pychecker to assert that a subclass does,
or does not, override a method of a base class. Yes, one could write that
test "by hand". The question is: how good is pychecker for this sort of
thing? Anyone have any experience?

2. Python's debugger is simple because Python so helpfully provides the
sys.settrace function. Has anyone used sys.settrace for unit testing? For
example, suppose you wanted to make a list of the methods that are exercised
by a test suite. The tracing function registered by sys.settrace could
easily do this. Etc.

3 In a slightly different direction, has someone used a simulation of
aspect-oriented programming in Python to make statements about test
coverage, or for other testing purposes?

Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream email: ed*******@chart er.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------
Jul 18 '05 #1
2 1807
On Tue, Nov 18, 2003 at 04:11:18PM -0600, Edward K. Ream wrote:
Has anyone used tools like pychecker (or even Python's own debugger or
profiler) during unit testing? Here are some things that might be natural
to do:

1. pychecker can run all kinds of fancy tests on code. I'm wondering
whether these tests could be incorporated somehow into individual unit
tests. For example, one might use pychecker to assert that a subclass does,
or does not, override a method of a base class. Yes, one could write that
test "by hand". The question is: how good is pychecker for this sort of
thing? Anyone have any experience?
Dunno. The way I typically write tests, I'll just call the method. If
it's not implemented (or implemented incorrectly), it won't behave how I
expect it to, and the test will fail.

It might be interesting to have a "pychecker test" provided by the test
framework. Similar to the common "at least import" tests, this could run
pychecker on all modules in a project, and fail if errors (and/or warnings)
are emitted. I've never looked inside pychecker, I don't know how easy or
hard this would be to implement.

2. Python's debugger is simple because Python so helpfully provides the
sys.settrace function. Has anyone used sys.settrace for unit testing? For
example, suppose you wanted to make a list of the methods that are exercised
by a test suite. The tracing function registered by sys.settrace could
easily do this. Etc.
A few test frameworks have support for reporting code coverage. No names
spring to mind at the moment, unfortunately. Also, a project I work on uses
this module:

http://www.ravenbrook.com/project/p4...st/coverage.py

in its unit tests to generate coverage statistics (the "test" can't ever
fail; a graph is generated based on its results, though; it is run for every
checkin).

3 In a slightly different direction, has someone used a simulation of
aspect-oriented programming in Python to make statements about test
coverage, or for other testing purposes?


Not exactly sure what you're getting at here.
Jp

Jul 18 '05 #2

"Edward K. Ream" <ed*******@char ter.net> wrote in message
news:vr******** ****@corp.super news.com...
Has anyone used tools like pychecker (or even Python's own debugger or
profiler) during unit testing? Here are some things that might be natural
to do:

1. pychecker can run all kinds of fancy tests on code. I'm wondering
whether these tests could be incorporated somehow into individual unit
tests. For example, one might use pychecker to assert that a subclass does, or does not, override a method of a base class. Yes, one could write that
test "by hand". The question is: how good is pychecker for this sort of
thing? Anyone have any experience?
I don't have any experiance, but the statement on the project page
http://pychecker.sourceforge.net/
doesn't suggest that it can do what you mention. It's more a static
analyzer for common problems.

That said, it might be a good project practice that all code needs to
pass pychecker before it can be committed.

Also, I'd like to know how you write that kind of test 'by hand.'
I can certainly see checking a single class for a manditory override /
not override, but I can't see exactly how you'd check *all* subclasses
for that condition without building a lot of infrastructure. You would at
least have to *find* all the class definitions.
2. Python's debugger is simple because Python so helpfully provides the
sys.settrace function. Has anyone used sys.settrace for unit testing? For example, suppose you wanted to make a list of the methods that are exercised by a test suite. The tracing function registered by sys.settrace could
easily do this. Etc.
There are at least two coverage tools that use the trace hook, and
I suspect there are others. One is accessable through the Vaults;
I don't know the rest of them. I've frequently thought that if you're
using XP or TDD, it might be a real good practice to run a coverage
checker. TDD is supposed to get you very close to 100% statement
coverage without extra effort.

When I want to check, I simply run my test suite under the coverage
tool. It takes about three times (or more) to run that way.
3 In a slightly different direction, has someone used a simulation of
aspect-oriented programming in Python to make statements about test
coverage, or for other testing purposes?
I don't understand this one at all...

John Roth

Thanks.

Edward
--------------------------------------------------------------------
Edward K. Ream email: ed*******@chart er.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------

Jul 18 '05 #3

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

Similar topics

1
1520
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(), and then add them to a TestCase class I have created. The tests seem to run, but they always seem to succeed - I have no idea why. Any ideas? Thomas ---snip---
7
2085
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 old lines at the end: if __name__ == "__main__": unittest.main() This is great, because each of the modules are runnable, and I can select classes or tests to run on the commandline if I want to. However, running all the tests from e.g. a...
0
2328
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 self.sampler = DisasterSampler()
1
1384
by: Olivier Langlois | last post by:
Hi, I have the following statement in my test : self.assertRaises(CDKeyException, ValidationObject.Validate, 1001,'NonExistantKey') and the test fails as if assertRaises was not catching the thrown exception:
0
11811
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
11404
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
11564
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
10903
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...
0
7601
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6411
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
6547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5149
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 we have to send another system
3
3756
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.