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

  • Home
  • SEARCH
  • 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 7796551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:24:23+00:00 2026-06-01T23:24:23+00:00

I just inherited some unit tests around Twisted Python, as shown below. While the

  • 0

I just inherited some unit tests around Twisted Python, as shown below.

While the test works, I don’t understand it conceptually.

Given the example below, can someone please explain the following things about it?

  • Why does this unit test ‘return page’?
  • Why aren’t there any calls to reactor.start()?
  • Any comments about the pros/cons of this approach, and perhaps others I could consider?

def setUp(self):
    self.listening_port = reactor.listenTCP(8118, server.Site(buildSite()))        

def tearDown(self):
    self.listening_port.stopListening()

def getUrl(self, extension=''):
    return 'http://localhost:%s/%s' % (self.listening_port.getHost().port, extension)

 def test(self):
     url = self.getUrl('foo')        
     def printResult(result):
         print result        
     page = getPage(url, method='POST').addCallback(printResult)
     return page
  • 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. Editorial Team
    Editorial Team
    2026-06-01T23:24:25+00:00Added an answer on June 1, 2026 at 11:24 pm

    Why does this unit test ‘return page’?

    Well, it’s not very clean. Twisted’s Trial unittest expect Deferred as result, with assert as callback. Here the callback is printResult, thus it will be evaluated to true for any non-empty string. I think more properly it should be:

    page = getPage(url, method='POST').addCallback(self.assertTrue)
    

    or

    page = getPage(url, method='POST').addCallback(self.assertIsNotNone)
    

    Why aren’t there any calls to reactor.start()?

    Because TestCase class takes care of that. And it’s also not using standard reactor.

    Since unit tests are avoiding real I/O and real time, they can usually
    avoid using a real reactor. The only exceptions to this are unit tests
    for a real reactor implementation. Unit tests for protocol
    implementations or other application code should not use a reactor.
    Unit tests for real reactor implementations should not use the global
    reactor, but should instead use
    twisted.internet.test.reactormixins.ReactorBuilder so they can be
    applied to all of the reactor implementations automatically. In no
    case should new unit tests use the global reactor.

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

Sidebar

Related Questions

Im trying to unit test a class in some Java code that I've inherited.
My PHP experience is rather limited. I've just inherited some stuff that looks odd
I'm looking at some vb.net code I just inherited, and cannot fathom why the
I've just inherited some code that uses HibernateEntityQuery and EJBQL restrictions. There's an activity
I inherited some release scripts that prepare and deploy a PHP webapp to around
I've just inherited this code in PHP which seems to do some kind of
I'm trying to find a way to write some unit-tests that can be used
I've inherited a legacy web application that has no unit tests in it. I'd
I just inherited some code, and have not seen this format before. Here's an
I just inherited some code which makes me uneasy: There is a testing library,

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.