[Tutor] Python&Pytest

Albert-Jan Roskam fomcl at yahoo.com
Fri Jun 12 10:18:27 CEST 2015


>________________________________
> From: Laura Creighton <lac at openend.se>
>To: Michelle Meiduo Wu <wumeid at hotmail.com> 
>Cc: lac at openend.se; "tutor at python.org" <tutor at python.org> 
>Sent: Thursday, June 11, 2015 11:11 PM
>Subject: Re: [Tutor] Python&Pytest
> 
>
>In a message of Thu, 11 Jun 2015 09:25:25 -0400, Michelle Meiduo Wu writes:
>>Hi there,
>>I'm looking for a language to write test scripts for our application. I read some document and found Pytest can be used to write simpler code compared with using unittest in Python. Does anybody know what's other pros and cons of using these two for writing test scripts?
>>Thank you,Michelle
>
>It is very much a 'try it and see what you like' sort of thing.
>



Hmm, I think it is possible to give some pros and cons. I have no experience with PyTest.
While I usually use unittest (just out of habit), I think nose is much easier and powerful.


* Unittest
Pros:
part of the Standard library
powerful, flexible

Cons:
need to declare a class to define one or more test cases (not so readable)

no (easy) test runner


* Doctest
Pros:
part of the Standard library
testable documentation


Cons:
Should be used for (testable) documentation, and nothing else
Basic use: easy. More advanced use: hard or impossible
No good for Python 2 & 3 code.


* Nose
Pros:
tests are readable; they are simply functions
generator tests
test runner for just about any other test module


cons:
not part of the Standard library
all tests pass in Python optimized mode (-O or -OO) --> because asserts are used!


* Pytest
???

* Dedicated test modules: numpy.testing, PyQt4.QtTest, etc.
Use whenever possible?


More information about the Tutor mailing list