Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
unittest vs py.test?
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
  Messages 26 - 41 of 41 - Collapse all  -  Translate all to Translated (View all originals) < Older 
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
 
Paul Rubin  
View profile  
 More options Apr 3 2005, 7:58 pm
Newsgroups: comp.lang.python
From: Paul Rubin <http://phr...@NOSPAM.invalid>
Date: 03 Apr 2005 16:58:59 -0700
Local: Sun, Apr 3 2005 7:58 pm
Subject: Re: unittest vs py.test?

"Terry Reedy" <tjre...@udel.edu> writes:
> > But assert statements vanish when you turn on the optimizer.  If
> > you're going to run your application with the optimizer turned on, I
> > certainly hope you run your regression tests with the optimizer on.

> I don't see why you think so.  Assertion statements in the test code make
> it harder, not easier for the test to pass.  Ditto, I believe, for any in
> the run code, if indeed there are any.

If the unit tests are expressed as assert statements, and the assert
statements get optimized away, then running the unit tests on the
optimized code can obviously never find any test failures.

    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.
Scott David Daniels  
View profile  
 More options Apr 3 2005, 8:58 pm
Newsgroups: comp.lang.python
From: Scott David Daniels <Scott.Dani...@Acm.Org>
Date: Sun, 03 Apr 2005 17:58:23 -0700
Local: Sun, Apr 3 2005 8:58 pm
Subject: Re: unittest vs py.test?

Paul Rubin wrote:
> "Terry Reedy" <tjre...@udel.edu> writes:

>>>But assert statements vanish when you turn on the optimizer.  If
>>>you're going to run your application with the optimizer turned on, I
>>>certainly hope you run your regression tests with the optimizer on.

>>I don't see why you think so.  Assertion statements in the test code make
>>it harder, not easier for the test to pass.  Ditto, I believe, for any in
>>the run code, if indeed there are any.

> If the unit tests are expressed as assert statements, and the assert
> statements get optimized away, then running the unit tests on the
> optimized code can obviously never find any test failures.

Any code depending upon __debug__ being 0 won't be tested.  Sometimes
test structures update values as a side-effect of tracking the debugging
state.  Not massively likely, but it makes for a scary environment when
your tests cannot be run on a non-debug version.

--Scott David Daniels
Scott.Dani...@Acm.Org


    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.
Roy Smith  
View profile  
 More options Apr 3 2005, 9:16 pm
Newsgroups: comp.lang.python
From: Roy Smith <r...@panix.com>
Date: Sun, 03 Apr 2005 21:16:28 -0400
Local: Sun, Apr 3 2005 9:16 pm
Subject: Re: unittest vs py.test?
Scott David Daniels <Scott.Dani...@Acm.Org> wrote:

> Any code depending upon __debug__ being 0 won't be tested.  Sometimes
> test structures update values as a side-effect of tracking the debugging
> state.  Not massively likely, but it makes for a scary environment when
> your tests cannot be run on a non-debug version.

> --Scott David Daniels
> Scott.Dani...@Acm.Org

What would happen if you defined

def verify (value):
   if not value:
      throw AssertionError

and then everyplace in your py.test suite where you would normally have
done "assert foo", you now do "verify (foo)"?  A quick test shows that it
appears to do the right thing.  I made a little test file:

------------------------------
#!/usr/bin/env python

def verify (value):
    if not value:
        raise AssertionError

class Test_foo:
    def test_one (self):
        assert 0

    def test_two (self):
        verify (0)
------------------------------

when I run that with "python py.test", I get two failures.  When I run it
with "python -O py.test", I get one pass and one fail, which is what I
expected to get if the assert gets optimized away.

The output is a little more verbose, since it shows the exception raised in
verify(), but it gives you a stack dump, so it's not that hard to look one
frame up and see where verify() was called from.

It's interesting that given the penchant for light-weight-ness in py.test,
that the default output is so verbose (and, to my mind, confusing) compared
to unittest.  I guess one could write their own output formatter and cut
down on the verbosity?


    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.
Peter Hansen  
View profile  
 More options Apr 4 2005, 9:33 am
Newsgroups: comp.lang.python
From: Peter Hansen <pe...@engcorp.com>
Date: Mon, 04 Apr 2005 09:33:11 -0400
Local: Mon, Apr 4 2005 9:33 am
Subject: Re: unittest vs py.test?

Raymond Hettinger wrote:
> [Peter Hansen]
>>(I'm not dissing py.test, and intend to check it
>>out.

> Not to be disrepectful, but objections raised by someone
> who hasn't worked with both tools equate to hot air.

Not to be disrespectful either, but criticism by
someone who has completely missed my point (and apparently
not read my posts) doesn't seem entirely fair.

At no time in this thread have I objected to py.test.
The sole point of my posts has been to object to those
claiming unittest as "heavy" when in the same
breath they seem to think you have to know all kinds
of details about TestSuite, TestRunner, and TestResult
objects just to use it.  I tried to demonstrate that
my way of using it appears to be on the same order of
"lightness" as some of the samples that were being used
to show how much lighter py.test was.

> Until you've exercised both packages, you haven't helped the OP
> whose original request was:  "Is there anybody out there who has
> used both packages and can give a comparative review?"

It seems possible to me that I might have helped him
solely by pointing out that unittest might not be so
"heavy" as some people claimed.  I got the impression
that he might be swayed by some unfounded claims not
even to look further at unittest, which I felt would
be a bad thing. (Not to say your comments are unfounded,
as clearly they are valid... I happen to believe mine
have been, in this thread, as well.  I guess you're
free to believe otherwise.  Cheers.)

-Peter


    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.
Roy Smith  
View profile  
 More options Apr 4 2005, 10:21 am
Newsgroups: comp.lang.python
From: r...@panix.com (Roy Smith)
Date: 4 Apr 2005 10:21:03 -0400
Local: Mon, Apr 4 2005 10:21 am
Subject: Re: unittest vs py.test?
Peter Hansen  <pe...@engcorp.com> wrote:

>It seems possible to me that I might have helped him
>solely by pointing out that unittest might not be so
>"heavy" as some people claimed.  I got the impression
>that he might be swayed by some unfounded claims not
>even to look further at unittest, which I felt would
>be a bad thing.

I'm the "him" referred to above.  I've been using unittest ever since
it was first added to the standard library (actually, now that I think
about it, I believe I may have been using it even before then).

And yes, I think unittest brings along a certain amount of baggage.
There is something attractive about having the same basic framework
work in many languages (PyUnit, JUnit, C++Unit, etc), but on the other
hand, it does add ballast.  I use it, I certainly don't hate it, but
on the other hand, there are enough things annoying about it that it's
worth investing the effort to explore alternatives.

From the few days I've been playing with py.test, I think I like what
I see, but it's got other issues.  The "optimization elides assert"
issue we've been talking about is one.

It's also neat that I can write unittest-style test classes or go the
simplier route of just writing static test functions, but there's a
certain amount of TIMTOWTDI (did I spell that right?) smell to that.

I'm also finding the very terse default output from unittest (basicly
a bunch of dots followed by "all N tests passed") highly preferable to
py.test's verbosity.

In short, I haven't made up my mind yet, but I do appreciate the input
I've gotten.


    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.
John J. Lee  
View profile  
 More options Apr 4 2005, 6:50 pm
Newsgroups: comp.lang.python
From: j...@pobox.com (John J. Lee)
Date: 04 Apr 2005 22:50:35 +0000
Local: Mon, Apr 4 2005 6:50 pm
Subject: Re: unittest vs py.test?

"Raymond Hettinger" <vze4r...@verizon.net> writes:
> [Peter Hansen]
> > (I'm not dissing py.test, and intend to check it
> > out.

> Not to be disrepectful, but objections raised by someone
> who hasn't worked with both tools equate to hot air.

[...]

Why?  Peter had a reasonable question which, AFAICT, doesn't depend on
any more detailed knowledge that what he had to work with.

What I don't understand about py.test (and trying it out seems
unlikely to answer this) is why it uses the assert statement.
unittest used to do that, too, but then it was pointed out that that
breaks when python -O is used, so unittest switched to self.assert_
&c.  Does py.test have some way around that?

John


    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.
Jeremy Bowers  
View profile  
 More options Apr 4 2005, 7:26 pm
Newsgroups: comp.lang.python
From: Jeremy Bowers <j...@jerf.org>
Date: Mon, 04 Apr 2005 18:26:29 -0500
Local: Mon, Apr 4 2005 7:26 pm
Subject: Re: unittest vs py.test?

On Mon, 04 Apr 2005 22:50:35 +0000, John J. Lee wrote:
> What I don't understand about py.test (and trying it out seems
> unlikely to answer this) is why it uses the assert statement.
> unittest used to do that, too, but then it was pointed out that that
> breaks when python -O is used, so unittest switched to self.assert_
> &c.  Does py.test have some way around that?

"Don't use -O because it doesn't do anything significant?"

Is this an issue in practice? (Honest question.) If -O did something
interesting I might use it, but I don't think it does.


    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.
Grig Gheorghiu  
View profile  
 More options Apr 4 2005, 7:51 pm
Newsgroups: comp.lang.python
From: "Grig Gheorghiu" <grig.gheorg...@gmail.com>
Date: 4 Apr 2005 16:51:36 -0700
Local: Mon, Apr 4 2005 7:51 pm
Subject: Re: unittest vs py.test?
py.test intercepts the assert statements before they are optimized
away. It's part of the profuse "magic" that py.test does.

Grig


    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.
Roy Smith  
View profile  
 More options Apr 4 2005, 7:59 pm
Newsgroups: comp.lang.python
From: Roy Smith <r...@panix.com>
Date: Mon, 04 Apr 2005 19:59:20 -0400
Local: Mon, Apr 4 2005 7:59 pm
Subject: Re: unittest vs py.test?
In article <pan.2005.04.04.23.26.28.468...@jerf.org>,
 Jeremy Bowers <j...@jerf.org> wrote:

> On Mon, 04 Apr 2005 22:50:35 +0000, John J. Lee wrote:
> > What I don't understand about py.test (and trying it out seems
> > unlikely to answer this) is why it uses the assert statement.
> > unittest used to do that, too, but then it was pointed out that that
> > breaks when python -O is used, so unittest switched to self.assert_
> > &c.  Does py.test have some way around that?

> "Don't use -O because it doesn't do anything significant?"

> Is this an issue in practice? (Honest question.) If -O did something
> interesting I might use it, but I don't think it does.

The following program produces different output depending on whether you
run it with -O or not:

try:
    assert 0
    print "I am running with -O"
except AssertionError:
    print "I'm not"


    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.
Jeremy Bowers  
View profile  
 More options Apr 4 2005, 9:59 pm
Newsgroups: comp.lang.python
From: Jeremy Bowers <j...@jerf.org>
Date: Mon, 04 Apr 2005 20:59:03 -0500
Local: Mon, Apr 4 2005 9:59 pm
Subject: Re: unittest vs py.test?

On Mon, 04 Apr 2005 19:59:20 -0400, Roy Smith wrote:
> The following program produces different output depending on whether you
> run it with -O or not:

> try:
>     assert 0
>     print "I am running with -O"
> except AssertionError:
>     print "I'm not"

But my question is whether it does anything *else*; if all -O does is
remove asserts (and set __debug__), and you're (not you personally)
complaining about -O removing asserts in testing code, the solution is to
not use -O. There's only a real *problem* if -O does something *more*,
such that you want one but not the other.

Up to this point, after years of Python use, I just ignore -O, because
it's not like it accelerates code or anything. (And I don't work on
embedded systems where my docstrings are a memory problem.) If everybody
else is like me, then if we even do have "real" optimizations, then we'll
actually need to use another switch.


    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.
Michael Hudson  
View profile  
 More options Apr 5 2005, 10:02 am
Newsgroups: comp.lang.python
From: Michael Hudson <m...@python.net>
Date: Tue, 5 Apr 2005 14:02:49 GMT
Local: Tues, Apr 5 2005 10:02 am
Subject: Re: unittest vs py.test?

Roy Smith <r...@panix.com> writes:
> In article <424e73a3.100782...@news.oz.net>, b...@oz.net (Bengt Richter)
> > Is there a package that is accessible without svn?

> That seems to be its weak point right now.

> Fortunately, you can get pre-built svn clients for many platforms
> (http://subversion.tigris.org/project_packages.html#binary-packages), and
> from there you just have to run a single command (svn get URL).

wget -r should work fine!

Cheers,
mwh

--
  All obscurity will buy you is time enough to contract venereal
  diseases.                                  -- Tim Peters, python-dev


    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.
Michael Hudson  
View profile  
 More options Apr 5 2005, 10:08 am
Newsgroups: comp.lang.python
From: Michael Hudson <m...@python.net>
Date: Tue, 5 Apr 2005 14:08:58 GMT
Local: Tues, Apr 5 2005 10:08 am
Subject: Re: unittest vs py.test?

For PyPy we wanted to do some things that the designers of unittest
obviously hadn't expected[1], such as formatting tracebacks
differently.  This was pretty tedious to do[2], involving things like
accessing __variables, defining subclasses of certain classes,
defining subclasses of other classes so the previous subclasses would
actually get used, etc.  I've not programmed in Java, but I imagine
this is what it feels like all the time...

(Not to knock unittest too much, we did manage to get the
customizations we needed done, but it wasn't fun).

Cheers,
mwh

[1] this in itself is hardly a criticism: there are many special
    things about PyPy.
[2] *this* is the criticism.

--
  Well, you pretty much need Microsoft stuff to get misbehaviours
  bad enough to actually tear the time-space continuum.  Luckily
  for you, MS Internet Explorer is available for Solaris.
                              -- Calle Dybedahl, alt.sysadmin.recovery


    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.
Peter Hansen  
View profile  
 More options Apr 5 2005, 10:42 am
Newsgroups: comp.lang.python
From: Peter Hansen <pe...@engcorp.com>
Date: Tue, 05 Apr 2005 10:42:33 -0400
Local: Tues, Apr 5 2005 10:42 am
Subject: Re: unittest vs py.test?

Michael Hudson wrote:
> Peter Hansen <pe...@engcorp.com> writes:
>>Where was all that weight that unittest supposedly
>>has?

> For PyPy we wanted to do some things that the designers of unittest
> obviously hadn't expected[1], such as formatting tracebacks
> differently.  This was pretty tedious to do[2],

I'd agree with that!  The guts of unittest I find to
be somewhat opaque, and not straightforward to extend.
Trying to do so here has also proven tedious, though
ultimately feasible, as you say the PyPy folks have
found.

Which, in the end, is precisely why I just use the
simplest vanilla approach that I can, no different
than anything done, for example, in the excellent
chapter on testing in http://www.diveintopython.org
or other examples of using unittest.

unitttest is surely not the be all and end all of
Python unit testing frameworks...  but it's one of
the batteries included in the standard distribution,
and it's pretty trivial to get started using it,
unless maybe you try to go by the documentation instead
of by the examples...

-Peter


    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.
Bengt Richter  
View profile  
 More options Apr 5 2005, 9:33 pm
Newsgroups: comp.lang.python
From: b...@oz.net (Bengt Richter)
Date: Wed, 06 Apr 2005 01:33:06 GMT
Local: Tues, Apr 5 2005 9:33 pm
Subject: Re: unittest vs py.test?

On Tue, 5 Apr 2005 14:02:49 GMT, Michael Hudson <m...@python.net> wrote:
>Roy Smith <r...@panix.com> writes:

>> In article <424e73a3.100782...@news.oz.net>, b...@oz.net (Bengt Richter)
>> > Is there a package that is accessible without svn?

>> That seems to be its weak point right now.

>> Fortunately, you can get pre-built svn clients for many platforms
>> (http://subversion.tigris.org/project_packages.html#binary-packages), and
>> from there you just have to run a single command (svn get URL).

>wget -r should work fine!

If you'll bear with my laziness, what should replace "should work fine!" in that?
TIA

Regards,
Bengt Richter


    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.
BJörn Lindqvist  
View profile  
 More options Apr 6 2005, 12:43 pm
Newsgroups: comp.lang.python
From: BJörn Lindqvist <bjou...@gmail.com>
Date: Wed, 6 Apr 2005 18:43:43 +0200
Local: Wed, Apr 6 2005 12:43 pm
Subject: Re: unittest vs py.test?
py.test is awesome, but there is one slight flaw in it. It produces to
much output. All I want to see when all tests pass is "All X passes
succeded!" (or something similar). py.test's output can be
distracting.

--
mvh Björn


    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.
Roy Smith  
View profile  
 More options Apr 6 2005, 1:19 pm
Newsgroups: comp.lang.python
From: r...@panix.com (Roy Smith)
Date: 6 Apr 2005 13:19:12 -0400
Local: Wed, Apr 6 2005 1:19 pm
Subject: Re: unittest vs py.test?

<bjou...@gmail.com> wrote:
>py.test is awesome, but there is one slight flaw in it. It produces to
>much output. All I want to see when all tests pass is "All X passes
>succeded!" (or something similar). py.test's output can be
>distracting.

I agree.

    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 < Older 
« Back to Discussions « Newer topic     Older topic »

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