473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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*******@charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------
Jul 18 '05 #1
2 1788
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*******@charter.net> wrote in message
news:vr************@corp.supernews.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*******@charter.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
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
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...
0
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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
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...

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.