Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93870

Re: Noob in Python. Problem with fairly simple test case

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; '(using': 0.07; 'subject:test': 0.07; 'works.': 0.07; 'cc:addr:python-list': 0.09; 'blocked': 0.09; 'it;': 0.09; 'spawn': 0.09; 'wrong,': 0.09; 'thread': 0.10; 'output': 0.13; 'def': 0.13; 'wed,': 0.15; 'intermediate': 0.15; 'server,': 0.15; '"hello': 0.16; 'end-to- end': 0.16; 'example)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'parts.': 0.16; 'self.server': 0.16; 'setup(self):': 0.16; 'subject:Problem': 0.16; 'subject:case': 0.16; 'subject:simple': 0.16; 'useless': 0.16; 'wrote:': 0.16; 'obviously': 0.16; 'debugging': 0.18; 'instance,': 0.18; 'stick': 0.18; 'test.': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'otherwise,': 0.20; 'saying': 0.22; 'init': 0.22; 'trying': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'testing': 0.25; "i've": 0.25; "doesn't": 0.26; 'external': 0.27; 'figure': 0.27; 'error': 0.27; 'handling': 0.27; 'parameters': 0.27; 'message- id:@mail.gmail.com': 0.27; 'pieces': 0.27; 'values': 0.28; 'about.': 0.29; 'asks': 0.29; 'block,': 0.29; 'blocking': 0.29; 'other,': 0.29; "i'm": 0.30; 'print': 0.30; 'server.': 0.30; 'code': 0.30; '15,': 0.30; 'probably': 0.31; 'skip:s 30': 0.31; 'another': 0.32; "can't": 0.32; 'possibly': 0.32; 'maybe': 0.33; 'getting': 0.33; 'run': 0.33; 'problem': 0.33; 'http': 0.33; 'surprised': 0.33; 'running': 0.34; 'server': 0.34; 'gets': 0.35; 'gives': 0.35; 'received:google.com': 0.35; 'on,': 0.35; 'could': 0.35; 'attempt': 0.35; 'jason': 0.35; 'something': 0.35; 'asking': 0.35; 'sometimes': 0.35; 'but': 0.36; 'cases': 0.36; 'smaller': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'method': 0.37; 'starting': 0.37; 'things': 0.38; 'doing': 0.38; "won't": 0.38; 'reports': 0.38; 'anything': 0.38; 'several': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'why': 0.39; 'goes': 0.39; 'test': 0.39; 'sure': 0.39; 'does': 0.39; "didn't": 0.39; 'rather': 0.39; 'subject:with': 0.40; 'still': 0.40; 'some': 0.40; 'easy': 0.60; 'your': 0.60; "you'll": 0.61; 'hope': 0.61; 'watch': 0.62; 'making': 0.62; 'more': 0.63; 'techniques': 0.65; 'offering': 0.66; 'forecast': 0.66; 'intent': 0.66; 'python-list': 0.66; 'here': 0.66; 'results': 0.66; 'cut': 0.67; 'subject:. ': 0.67; 'receive': 0.71; 'jul': 0.72; 'yourself': 0.73; '"it': 0.84; 'calculations': 0.84; 'chrisa': 0.84; 'commenting': 0.84; 'console,': 0.84; 'construct': 0.84; 'deductions': 0.84; 'ever.': 0.84; 'flag.': 0.84; 'kicking': 0.84; 'out!': 0.84; 'suspecting': 0.84; 'text/plain': 0.84; 'to:none': 0.91; 'probe': 0.91; 'technique': 0.93; 'placement': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=i2DJ4/d6IRw+0czfG7COStQhmsyB0kAS5Ylaxf/05UI=; b=0Vz5t2pxnjPgBdWoqYuLQOS1lfet68XKYkzu+q46SVn0sd51eTVuMg0rYc5orzlHUI PABt+S9pnsNHPL3ds81t672LOcIYTyWAJrKCBSAOBPOk9Z+Zfr/vIDySUQ+vVRPnT+7x OWqXf5JKZBK4SVAjipgko6pmilHfmrsDSsK/9ZXxOdFPbUIbncAbo77BUb9A+pD0cBYC vYeyQn1nKACfFeT0DAIxTYVdbroiWX/WHDcYT8hSyS+vbjJXPS5DTwG78Qn+8fd2zeIP v2J1AVDBd0djwX6lnMdvZ2EK/vDikb7+SPA/ogRKj6Dx0rj06IotZCw2BoA13w0aiPdS TXpw==
MIME-Version 1.0
X-Received by 10.50.7.104 with SMTP id i8mr9718285iga.50.1436962306629; Wed, 15 Jul 2015 05:11:46 -0700 (PDT)
In-Reply-To <0165e508-b3b4-4a95-b1bb-e115893056f8@googlegroups.com>
References <0165e508-b3b4-4a95-b1bb-e115893056f8@googlegroups.com>
Date Wed, 15 Jul 2015 22:11:46 +1000
Subject Re: Noob in Python. Problem with fairly simple test case
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.539.1436962316.3674.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1436962316 news.xs4all.nl 2898 [2001:888:2000:d::a6]:34804
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93870

Show key headers only | View raw


On Wed, Jul 15, 2015 at 9:44 PM, Jason P. <suscricions@gmail.com> wrote:
> I can't understand very well what's happening. It seems that the main thread gets blocked listening to the web server. My intent was to spawn another process for the server independent of the test. Obviously I'm doing something wrong. I've made several guesses commenting pieces of code (tearDown method for example) but I didn't manage to solve the problem(s).
>

When you find yourself making guesses to try to figure out what's
going on, here are two general tips:

1) Cut out as many pieces as you can. Test one small thing at a time.
2) If In Doubt, Print It Out! Stick print() calls into the code at key
places, displaying the values of parameters or the results of
intermediate calculations - or just saying "Hi, I'm still here and I'm
running!".

For #1, I would recommend first just trying to get the web service
going. Can you connect (using an external program) on port 8000 and
receive a text/plain HTTP response saying "Hello World!"? Never mind
about the test for the moment.

And for #2, judicious placement of console output will help you figure
out things you're not sure about. For instance, you're suspecting that
the main thread is getting blocked handling the web server. Easy way
to check:

    def setUp(self):
        # Start the forecast server
        self.server = ForecastServer()
        self.server.start(webservice.app)

Just before you construct the server, print something out. After
you've constructed it but before you call start(), print something
out. And after starting it, print something out. Then run the program.
If you see the first line and no other, then it's blocking during the
construction. Other deductions I'm sure you can figure out.

One small point: Probe even things that you think are trivial. In the
above example, I cannot see any reason why constructing
ForecastServer() could possibly block, because its init does nothing
but set a flag. But you can get surprised by things sometimes - maybe
the problem is actually that you're not running the code you think you
are, but there's some other ForecastServer kicking in, and it's
synchronous rather than subprocess-based.

End-to-end testing is all very well, but when something goes wrong,
the key is to break the program down into smaller parts. Otherwise,
all you have is "it doesn't work", which is one of the most useless
error reports ever. If someone comes to python-list saying "it doesn't
work", we'll be asking him/her to give a lot more details; if your
aunt asks you for help printing out a document because "it doesn't
work", you'll probably have to go over and watch her attempt it; and
it's the same with your test cases - you make them tell you more
details.

Hope that helps! The techniques I'm offering are completely
problem-independent, and even language-independent. IIDPIO debugging
works in anything that gives you a console, which is pretty much
everything - maybe it won't be print() but logging.debug(), but the
same technique works.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Noob in Python. Problem with fairly simple test case "Jason P." <suscricions@gmail.com> - 2015-07-15 04:44 -0700
  Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-15 22:11 +1000
    Re: Noob in Python. Problem with fairly simple test case Larry Hudson <orgnut@yahoo.com> - 2015-07-15 20:01 -0700
      Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-16 13:11 +1000
        Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-15 20:33 -0700
          Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-16 13:44 +1000
            Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 13:03 -0700
              Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 06:11 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 13:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Emile van Sebille <emile@fenx.com> - 2015-07-16 14:27 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 09:24 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 17:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 12:44 +1000
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 13:01 +1000
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 16:47 +1000
                Re: Noob in Python. Problem with fairly simple test case wxjmfauth@gmail.com - 2015-07-17 02:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 20:57 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-16 21:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-17 15:16 +1000
                Re: Noob in Python. Problem with fairly simple test case Steven D'Aprano <steve@pearwood.info> - 2015-07-17 16:38 +1000
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-17 10:57 -0700
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-17 22:38 +0200
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-18 14:12 -0700
                Re: Noob in Python. Problem with fairly simple test case Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-17 23:03 +0100
                Re: Noob in Python. Problem with fairly simple test case Terry Reedy <tjreedy@udel.edu> - 2015-07-17 18:45 -0400
                Re: Noob in Python. Problem with fairly simple test case wxjmfauth@gmail.com - 2015-07-18 00:30 -0700
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-18 16:18 -0700
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-19 11:09 +0200
                Re: Noob in Python. Problem with fairly simple test case Rick Johnson <rantingrickjohnson@gmail.com> - 2015-07-19 10:25 -0700
                Re: Noob in Python. Problem with fairly simple test case MRAB <python@mrabarnett.plus.com> - 2015-07-19 18:45 +0100
                Re: Noob in Python. Problem with fairly simple test case Laura Creighton <lac@openend.se> - 2015-07-19 19:50 +0200
                Off-topic: Europe [was Re: Noob in Python. Problem with fairly simple test case] Steven D'Aprano <steve@pearwood.info> - 2015-07-20 12:30 +1000
                Re: Noob in Python. Problem with fairly simple test case Emile van Sebille <emile@fenx.com> - 2015-07-17 16:15 -0700
                Re: Noob in Python. Problem with fairly simple test case Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-17 08:26 -0400
        Re: Noob in Python. Problem with fairly simple test case Larry Hudson <orgnut@yahoo.com> - 2015-07-16 20:49 -0700
    Re: Noob in Python. Problem with fairly simple test case "Jason P." <suscricions@gmail.com> - 2015-07-21 10:38 -0700
      Re: Noob in Python. Problem with fairly simple test case Chris Angelico <rosuav@gmail.com> - 2015-07-22 03:48 +1000

csiph-web