Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 100167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:31:39+00:00 2026-05-11T00:31:39+00:00

I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =

  • 0

I currently have a unittest.TestCase that looks like..

class test_appletrailer(unittest.TestCase):     def setup(self):         self.all_trailers = Trailers(res = '720', verbose = True)      def test_has_trailers(self):         self.failUnless(len(self.all_trailers) > 1)      # ..more tests.. 

This works fine, but the Trailers() call takes about 2 seconds to run.. Given that setUp() is called before each test is run, the tests now take almost 10 seconds to run (with only 3 test functions)

What is the correct way of caching the self.all_trailers variable between tests?

Removing the setUp function, and doing..

class test_appletrailer(unittest.TestCase):     all_trailers = Trailers(res = '720', verbose = True) 

..works, but then it claims ‘Ran 3 tests in 0.000s’ which is incorrect.. The only other way I could think of is to have a cache_trailers global variable (which works correctly, but is rather horrible):

cache_trailers = None class test_appletrailer(unittest.TestCase):     def setUp(self):         global cache_trailers         if cache_trailers is None:             cache_trailers = self.all_trailers = all_trailers = Trailers(res = '720', verbose = True)         else:             self.all_trailers = cache_trailers 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:31:40+00:00Added an answer on May 11, 2026 at 12:31 am

    How about using a class member that only gets initialized once?

    class test_appletrailer(unittest.TestCase):      all_trailers = None      def setup(self):         # Only initialize all_trailers once.         if self.all_trailers is None:             self.__class__.all_trailers = Trailers(res = '720', verbose = True) 

    Lookups that refer to self.all_trailers will go to the next step in the MRO — self.__class__.all_trailers, which will be initialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This link might be helpful. May 11, 2026 at 10:05 am
  • added an answer Yes, PHP can be be used to connect to SOAP… May 11, 2026 at 10:05 am
  • added an answer In C# 3.0 and later, auto-implemented properties make property-declaration more… May 11, 2026 at 10:05 am

Related Questions

I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
I currently have a fairly robust server-side validation system in place, but I'm looking
I currently have a class and I'm trying to create an easy GUI to
I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView
I currently have a DetailsView in ASP.NET that gets data from the database based
I currently have a couple of SVN repositories hosted at Unfuddle and I'd like
I currently have a list view which has several rows of data and I
I currently have a listview and I want to add an appropriate icon to
I currently have a collection with a HasChanges property on it (each object in
I currently have a source control folder in TFS with all of my source

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.