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

Needed class whose instances are many test cases

I have scinario like I have to Create resource(in __init__()) Before
Running a set of testcases and then In Testcases resources are going to
used and then It will cleared off after Running the testcases by
destructor __del__()
import unittest
import time

class app_adminfunc(unittest.TestCase):

def __init__(self, method = 'runTests'):
unittest.TestCase.__init__(self, method)
#------------Resource Creation --------

def __del__(self):
#--------------Resource Deletion -----------------

def test01-----
def test02-----
........
.....

But in this above code Problem is that __init__() called at each time
when the Testcase is run ,But i want Single time run of the Init Prior
to run of each tests inside the class .
Can Anybody help me on this ?

Nov 11 '05 #1
5 1469
>>>>> "Sumit" == Sumit <su*********@gmail.com> writes:

Sumit> I have scinario like I have to Create resource(in
Sumit> __init__()) Before Running a set of testcases and then In
Sumit> Testcases resources are going to used and then It will
Sumit> cleared off after Running the testcases by destructor
Sumit> __del__() import unittest import time

Sumit> class app_adminfunc(unittest.TestCase):

Sumit> def __init__(self, method = 'runTests'):
Sumit> unittest.TestCase.__init__(self, method)
Sumit> #------------Resource Creation --------

Sumit> def __del__(self): #--------------Resource
Sumit> Deletion -----------------

Sumit> def test01----- def test02----- ....... ....

Sumit> But in this above code Problem is that __init__() called at
Sumit> each time when the Testcase is run ,But i want Single time
Sumit> run of the Init Prior to run of each tests inside the class
Sumit> . Can Anybody help me on this ?

The unittest module runs a setUp and tearDown before each test case.
If that is too high-frequency, why not just do something like

class app_adminfunc(unittest.TestCase):
def setUp(self): pass
def tearDown(self): pass
def allYourTestCase(self):
def test01(): pass
def test02(): pass

since python is so mellow about nesting functions and classes and
such.

HTH,
Chris
Nov 11 '05 #2
Sumit <su*********@gmail.com> wrote:
I have scinario like I have to Create resource(in __init__()) Before
Running a set of testcases and then In Testcases resources are going
to used and then It will cleared off after Running the testcases by
destructor __del__()


This is a poor design; your tests will each be starting in a different
state, and will likely not run the same way if run in a different
order, making them fragile.

Test cases should each run individually, from a known state, and not
depend on any other tests. You can define a fixture for several tests
in the unittest.TestCase methods setUp() and tearDown(), to establish
and clear up respectively for each test.

--
\ "When I wake up in the morning, I just can't get started until |
`\ I've had that first, piping hot pot of coffee. Oh, I've tried |
_o__) other enemas..." -- Emo Philips |
Ben Finney
Nov 11 '05 #3
In article <dl**********@rose.polar.local>,
Ben Finney <bi****************@benfinney.id.au> wrote:
This is a poor design; your tests will each be starting in a different
state, and will likely not run the same way if run in a different
order, making them fragile.

Test cases should each run individually, from a known state, and not
depend on any other tests. You can define a fixture for several tests
in the unittest.TestCase methods setUp() and tearDown(), to establish
and clear up respectively for each test.


In general, I certainly agree with the above. The problem is that
sometimes setup is so expensive, it becomes impractical to do a full
setup/teardown cycle for each test.
Nov 11 '05 #4
Roy Smith <ro*@panix.com> wrote:
Ben Finney <bi****************@benfinney.id.au> wrote:
Test cases should each run individually, from a known state, and
not depend on any other tests. You can define a fixture for
several tests in the unittest.TestCase methods setUp() and
tearDown(), to establish and clear up respectively for each test.


In general, I certainly agree with the above. The problem is that
sometimes setup is so expensive, it becomes impractical to do a full
setup/teardown cycle for each test.


That's what mock objects are for. The test fixture should be minimal,
having only the interface needed to test that the production code does
what it should, with almost no functionality behind that interface.

<URL:http://pmock.sourceforge.net/>

--
\ "I always had a repulsive need to be something more than |
`\ human." -- David Bowie |
_o__) |
Ben Finney
Nov 12 '05 #5
Thanks for comments
..setup() is going the Run Before every testcase Run. But i need to
create resource for set of testcases , it is one time only . I can not
create at every instant before testcases Run . thats why
Unittest.testsuit is goingto help me out . There __init__() can be Run
One time and the resource can be create one time for set of tests.

Nov 22 '05 #6

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

Similar topics

0
by: Gonçalo Rodrigues | last post by:
Hi, I have a problem with threads and sockets. I'll try to describe the problem in words with pseudo-code. I've been working on a few classes to make it easier to work with threads. This...
4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
7
by: Daniel Nogradi | last post by:
What is the simplest way to instantiate all classes that are subclasses of a given class in a module? More precisely I have a module m with some content: # m.py class A: pass class x( A ):...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
5
by: pgrazaitis | last post by:
I cant seem to get my head wrapped around this issue, I have myself so twisted now there maybe no issue! Ok so I designed a class X that has a few members, and for arguments sake one of the...
21
by: Nikolaus Rath | last post by:
Hello, Can someone explain to me the difference between a type and a class? After reading http://www.cafepy.com/article/python_types_and_objects/ it seems to me that classes and types are...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
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
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...
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
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...
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.