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


Groups > comp.lang.python > #6101

Re: Unit testing beginner question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'raised': 0.07; 'called.': 0.09; 'exception:': 0.09; 'lambda:': 0.09; 'subject:beginner': 0.09; 'pm,': 0.10; 'exception': 0.12; 'wrote:': 0.14; 'argument': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'call.': 0.19; 'cheers,': 0.19; 'header:In- Reply-To:1': 0.21; 'cc:2**0': 0.22; 'subject:question': 0.23; 'cc:no real name:2**0': 0.23; 'last):': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'function': 0.25; 'received:209.85.161': 0.26; 'object': 0.26; 'pass': 0.27; 'message-id:@mail.gmail.com': 0.28; 'work:': 0.29; 'cc:addr:python.org': 0.30; 'second': 0.30; 'typeerror:': 0.30; "can't": 0.32; 'error': 0.33; '8bit%:3': 0.35; 'test': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; 'received:209': 0.39; 'getting': 0.40; "'nonetype'": 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=ViPjO+fSW7GX/Pv/Lz68AUd+F/gQZaE2wM5BzljN3kQ=; b=lhhqyuQb5CLfRQbMYZ5wqfH9tExtyyI2v/IcgtIf2kAj5EST4uNOgNTSiQpsVMYF6w Z2nuV3slGhCMWXzxi1lztcLrJUNllIWLi/5/3ITLl803qvLFHBgVQ8tdRrbkytYaYTSB O5lZZQuOv7eFKGA7aY8uzVaHGZR+JoLJ2g+Ho=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=kqxz64ZqCSRhnd2ZIiPbUGCTaNFIOS9R8p12c6X9bxkqpOWWR5x9wG8dZiZbqtPoYg UnaLLVopAVcB40uP9RxV5PUTwZ8Bzw0SRCu9VubR3xd5jTym2BY/BpQcTx8OmNnBz66A Hw7sys+RpECL4fAq835WwRr47GS/tDNk7PoUM=
MIME-Version 1.0
In-Reply-To <b34bbd5b-bd87-43e0-85a9-1cfbdcc4ca8c@y12g2000yqh.googlegroups.com>
References <b34bbd5b-bd87-43e0-85a9-1cfbdcc4ca8c@y12g2000yqh.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 23 May 2011 16:46:52 -0600
Subject Re: Unit testing beginner question
To Andrius <andrius.a@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1991.1306191316.9059.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 82.94.164.166
X-Trace 1306191317 news.xs4all.nl 49046 [::ffff:82.94.164.166]:56195
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6101

Show key headers only | View raw


On Mon, May 23, 2011 at 4:30 PM, Andrius <andrius.a@gmail.com> wrote:
> and I am expecting test to pass, but I am getting exception:
> Traceback (most recent call last):
>    self.assertRaises(TypeError, self.testListNone[:1])
> TypeError: 'NoneType' object is unsubscriptable
>
> I thought that assertRaises will pass since TypeError exception will
> be raised?

The second argument to assertRaises must be a function that
assertRaises will call.  assertRaises can't catch the error above
because it is raised when the argument is evaluated, before
assertRaises has even been called.

This would work:

self.assertRaises(TypeError, lambda: self.testListNone[:1])

Cheers,
Ian

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


Thread

Unit testing beginner question Andrius <andrius.a@gmail.com> - 2011-05-23 15:30 -0700
  Re: Unit testing beginner question Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-23 16:46 -0600
    Re: Unit testing beginner question Roy Smith <roy@panix.com> - 2011-05-23 20:19 -0400

csiph-web