Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
unittest & setup
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gabriel Genellina  
View profile  
 More options Nov 4, 3:42 pm
Newsgroups: comp.lang.python
From: "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
Date: Wed, 04 Nov 2009 01:42:55 -0300
Local: Wed, Nov 4 2009 3:42 pm
Subject: Re: unittest & setup
En Wed, 04 Nov 2009 01:02:24 -0300, Jonathan Haddad <j...@jonhaddad.com>  
escribió:

> I've got a class, in the constructor it loads a CSV file from disc.  I'd
> like only 1 instance of the class to be instantiated.  However, when  
> running
> multiple unit tests, multiple instances of the class are created.  What's
> the best way for me to avoid this?  It takes about a few seconds to load  
> the
> CSV file.

Use a factory function:

_instance = None
def createFoo(parameters):
   if _instance is None:
     _instance = Foo(parameters)
   return _instance

and replace all occurrences of Foo(parameters) with createFoo(parameters).  
For new-style classes, you may override the __new__ method instead.

Perhaps I didn't understand your problem correctly because this is  
unrelated to unit testing...

--
Gabriel Genellina


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Riopel  
View profile  
 More options Nov 5, 1:08 am
Newsgroups: comp.lang.python
From: Joe Riopel <goo...@gmail.com>
Date: Wed, 4 Nov 2009 09:08:12 -0500
Local: Thurs, Nov 5 2009 1:08 am
Subject: Re: unittest & setup

On Tue, Nov 3, 2009 at 11:02 PM, Jonathan Haddad <j...@jonhaddad.com> wrote:
> I've got a class, in the constructor it loads a CSV file from disc.  I'd
> like only 1 instance of the class to be instantiated.  However, when running
> multiple unit tests, multiple instances of the class are created.  What's
> the best way for me to avoid this?  It takes about a few seconds to load the
> CSV file.

This post that might be worth reading, as it relates to testing with
singletons.

http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/

As is this

http://misko.hevery.com/code-reviewers-guide/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google