473,545 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pyunit: remove a test case on the fly

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 currently have an "isSupporte d" method in the TestCase classes that
return a bool by which the greater test harness decides whether to run
the enclosed test methods or not. We would like to have
per-test-method granularity, however, for essentially skipping that
particular test method; basically another isSupported call within the
individual methods. We took a quick look at such options as:
generating the entire test suite, then iterating through and renaming
SomeTestClass.t estSomeTest to SomeTestClass.S KIPsomeTest, and seeing if
PyUnit would skip it (since the method name no longer starts with
"test"). But this seemed pretty unwieldy. We have also considered
breaking up the test class to a number of smaller test classes and
calling isSupported with that finer-granularity set of test classes.
That is probably the easiest way, but we do still want to consider
alternatives.

Here's to hoping that other folks out there have had experience with
removing test methods on the fly, and have some wisdom to share.

Cheers

Jul 19 '05 #1
2 2105
On 15 Jun 2005 14:13:09 -0700, chris <ch*********@gm ail.com> wrote:
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).


Here's a simple approach imitating NUnit's CategoryAttribu te. I don't
know whether it'll work for you, it depends on what exactly
isSupported() does.

- kv
import unittest

def category(*test_ categories):
tc = frozenset(test_ categories)
def f(g):
if tc & frozenset(activ e_categories):
return g
# else return None,
# effectively removing test from TestCase
return f

active_categori es = ['mac', 'nt']

class T(unittest.Test Case):

@category('mac' )
def test_a(self):
print 'mac only'

@category('posi x')
def test_b(self):
print 'posix only'

@category('posi x', 'nt')
def test_c(self):
print 'posix or nt'

def test_d(self):
print 'platform-independent'
if __name__ == '__main__':
unittest.main()
Jul 19 '05 #2
chris wrote:
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 currently have an "isSupporte d" method in the TestCase classes that
return a bool by which the greater test harness decides whether to run
the enclosed test methods or not. We would like to have
per-test-method granularity, however, for essentially skipping that
particular test method; basically another isSupported call within the
individual methods. We took a quick look at such options as:
generating the entire test suite, then iterating through and renaming
SomeTestClass.t estSomeTest to SomeTestClass.S KIPsomeTest, and seeing if
PyUnit would skip it (since the method name no longer starts with
"test"). But this seemed pretty unwieldy. We have also considered
breaking up the test class to a number of smaller test classes and
calling isSupported with that finer-granularity set of test classes.
That is probably the easiest way, but we do still want to consider
alternatives.


ISTM you could write a custom TestLoader that filters the test names, then pass that loader to unittest.main() . For example, assuming a classmethod or staticmethod on the test case that filters test case names, something like this (not tested):

def MyTest(TestCase ):
@staticmethod
def isSupportedTest (testName):
return True

def testSomething.. .

class FilteringTestLo ader(TestLoader ):
def getTestCaseName s(self, testCaseClass):
names = TestLoader.getT estCaseNames(se lf, testCaseClass)
names = filter(testCase Class.isSupport edTest, names)
return names

unittest.main(t estLoader=Filte ringTestLoader( ))

You could do something similar with a FilteringTestSu ite if that fits your harness better.

Kent
Jul 19 '05 #3

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

Similar topics

2
2166
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 usable for current python version 2.4. Will you please tell me? Thank you. What are the advantages and disadvantages of unittest? Can somebody give...
12
55532
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are also removed) So far I have (val is value, ar is array, returns new array):
1
7783
by: Steve Jorgensen | last post by:
I was working with a friend on a project Monday night, and tried to run a pyunit test from Eclipse, and nothing seemed to happen. We finally figured out that the test is doing exactly what it's supposed to do, but the pyunit output isn't making it to the Eclipse console window. We get the same result if I run the module as a pyunit test...
1
1987
by: travislspencer | last post by:
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...
5
3540
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 something like this class getUsStatesTest( unittest.TestCase ):
1
1704
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 information if the tests were run with -v or -vv. yours, Noah
2
2795
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 remember - where. I am working on a complex testing application built over unittest module, and I need GUI interface that will alllow me to select tests...
0
1065
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 is the status message returned. For example, say that I send the commands "get" and "delete" for a given record to the database at the same...
15
50166
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
0
7415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7928
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...
1
7440
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...
0
7775
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...
0
5997
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5344
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...
0
4963
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...
0
3470
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...
0
726
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...

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.