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

Home Posts Topics Members FAQ

A script to run all of my project's pyunit tests

Hey All,

I am trying to write a script that runs all of my pyunit tests for me.
Ideally, I would like to be able to drop a new module into my
project's test subdirectory, and the testing script will pick it up
automatically.

At the moment, I have it working but it is kinda a kludge because
every TestCase must provide a function that returns a TestSuite for
all of its tests.

Here is the basic process and a stripped down version of the script:

1. Locate each `.py' file in my project's test subdirectory.
2. Import the module found in step 1.
3. Get a TestSuite of all of the tests in the module imported in step
2.
4. Add the TestSuite from step 3 to a growing list of suites.
5. Make one granddaddy TestSuite from the list of all those fetched in
steps 1 through 4.
6. Create a runner, pass it the uber TestSuite, and run all the tests.

My scripts to do these things is as follows:

================================================== ====================
import os, sys, unittest
from glob import glob

projHome = os.getenv("PROJ_HOME")
sys.path.insert(0, projHome + "/tests")
tests = []

for file in glob(projHome + "/tests/*.py"):
start = file.rfind("/") + 1
end = file.rfind(".")
moduleName = file[start:end]
module = __import__(moduleName)

tests.append(module.getTestSuite())
#-----------------------^
# The part that I'm not happy with.

allTests = unittest.TestSuite(tests)
runner = unittest.TextTestRunner(verbosity=2)

runner.run(allTests)
================================================== ====================

With this setup, every module has to have a `getTestSuite' function
that returns a TestSuite for the module. This is suboptimal and
annoying. The function looks like this is all of my TestCase
subclasses:

================================================== ====================
class MyTestCase(unittest.TestCase):
pass

def getTestSuite():
return suite

if __name__ == "__main__":
unittest.main()
else:
global suite

suite = unittest.makeSuite(MyTestCase, 'test')
================================================== ====================

The problem is that I can't figure out how to do something similar to
the TestCases' `unittest.makeSuite(MyTestCase, 'test')' in the script
that I'm using to run all of the tests.

If anyone has any help or suggestions, I would really appreciate it.

--
Regards,

Travis Spencer

Aug 19 '05 #1
1 1980
tr************@gmail.com wrote:
for file in glob(projHome + "/tests/*.py"):
start = file.rfind("/") + 1
end = file.rfind(".")
moduleName = file[start:end]
module = __import__(moduleName)
klass = module.__dict__[module.__name__]
tests.append(unittest.makeSuite(klass, "test"))
allTests = unittest.TestSuite(tests)
runner = unittest.TextTestRunner(verbosity=2)

runner.run(allTests)


This is still a kludge, but a different and less annoying one. It
works as long as the TestCase class and module have the same name.

Back to the drawing board...

--

Regards,

Travis Spencer

Aug 19 '05 #2

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

Similar topics

2
by: could ildg | last post by:
I want to know something about unittest these days, and since I'm learning python, I want to touch it through python. But when I found the newest pyunit is even so old, I wonder if it is still...
2
by: chris | last post by:
We have a number of TestCase classes that have multiple test methods. We are interested in removing any of the individual test methods on the fly (dynamically, at runtime, whatever). We...
2
by: Naveen Mukkelli | last post by:
Hi, Currently, I've got all my unit tests in a separate class in the same project. Instead of this, I'm planning to move all my tests in a separate project in a single solution. For...
31
by: Bob | last post by:
I have recently joined a healthcare company where I am the solo programmer. I am going to be starting work on a project. The management has asked me to provide an estimate of hours I am going to...
0
by: MarkusPoehler | last post by:
I have several classic ASP projects running on Webserver. I would like to implement some .net functionalities. Because I need the references I have to "upgrade" the existing ones wit a new .net...
5
by: Sakcee | last post by:
Hi I am trying to use pyUnit to create a framework for testing functions I am reading function name, expected output, from a text file. and in python generating dynamic test functions...
1
by: Noah | last post by:
Is there a way for a test case method in a class derived from unittest.TestCase to tell if the harness was started with the verbose option? I would like my test cases to print out a little extra...
2
by: volcano | last post by:
I am desperately looking for an info how to combine a testing application with decent GUI interface - the way most xUnits do. I believe I have seen something about using Tkinter, but I do not...
0
by: winston.yang | last post by:
Is it possible to use PyUnit to test with multiple threads? I want to send many commands to a database at the same time. The order of execution of the commands is indeterminate, and therefore, so...
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
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...
1
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...
0
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
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
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...
0
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
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
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.