473,399 Members | 2,159 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,399 software developers and data experts.

Organising unit tests

I have a number of unit tests organised hierarchically, all of which
inherit fixtures from a base class. To run these all at once I started
out using

from basic import map, directionalpan, layerorder, layervisibility,
listlayers, streamlayerlist
# ... lots more ...

suite0 =
unittest.TestLoader().loadTestsFromTestCase(direct ionalpan.TestPan)
suite1 =
unittest.TestLoader().loadTestsFromTestCase(layero rder.TestLayerorder)
# ... lots more ...

alltests = unittest.TestSuite([suite0
, suite1
....])
unittest.TextTestRunner(verbosity=2).run(alltests)

Which is unmaintainable. the TestLoader docs warn that
loadTestsFromModule will not play nicely with my situation and indeed
if I try

suite0 = unittest.TestLoader().loadTestsFromModule(basic)

then run the tests, it hasn't picked any up. I suppose I could collect
and run the tests with a shell script...what are my options here to
avoid hardcoding and maintaining the list of tests, and how is it
normally done?

Thanks.

Sep 29 '06 #1
1 1470
OK, so I'm trying to collect the tests with python and add them to the
test suite dynamically, but I have a problem with module names. Here's
what I've got:
#########################
import os
from os.path import join
import unittest

alltests = unittest.TestSuite()

def mightBeATest(f):
#TODO check whether it really is a test
return f.endswith('.py') and f != '__init__.py'

def isModule(d):
if not os.path.isdir(d):
return False
for f in os.listdir(d):
if f == '__init__.py':
return True
return False
def getTestsFromDir(dir, currentmod):
for f in os.listdir(dir):
if not f.startswith('.'):
if isModule(f):
#TODO how to check whether we are several modules in?
mod = __import__(f)
getTestsFromDir(os.path.join(dir, f), mod)
elif mightBeATest(os.path.join(dir, f)):
fname, etx = os.path.splitext(f)
print 'adding test
with',('alltests.addTests(unittest.TestLoader().lo adTestsFromTestCase('+(currentmod.__dict__[fname])+'))')

eval('alltests.addTests(unittest.TestLoader().load TestsFromTestCase('+currentmod.__dict__[fname]+'))')
getTestsFromDir(os.curdir, None)
print alltests.countTestCases()
############################

it's importing and referring to the current module that I have a
problem with...it gives me a key error.

Sep 29 '06 #2

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

Similar topics

6
by: Tom Verbeure | last post by:
Hello All, so I'm now convinced that unit testing is really the way to go and I want to add it to an existing project. The first thing that I find out, is that, well, it's hard work. Harder than...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
72
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: ...
6
by: Michael Bray | last post by:
I've just inherited a fairly large project with multiple classes. The developer also wrote a huge number of unit tests (using NUnit) to validate that the classes work correctly. However, I don't...
5
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...
176
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...
1
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...
6
by: Vyacheslav Maslov | last post by:
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...
5
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 Team Edition for Software Developers I've used the wizard under the Test menu to create a bunch of unit tests. When I click "Test -Start Selected Test Project...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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,...
0
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...

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.