I've used the standard unittest (pyunit) module on a few projects in the
past and have always thought it basicly worked fine but was just a little
too complicated for what it did.
I'm starting a new project now and I'm thinking of trying py.test
( http://codespeak.net/py/current/doc/test.html). It looks pretty cool from
the docs. Is there anybody out there who has used both packages and can
give a comparative review? 41 10259
[Roy Smith] I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did.
I'm starting a new project now and I'm thinking of trying py.test (http://codespeak.net/py/current/doc/test.html). It looks pretty cool from the docs. Is there anybody out there who has used both packages and can give a comparative review?
I've used both and found py.test to be effortless and much less verbose.
For more complex testing strategies, py.test is also a winner. The generative
tests are easier to write than crafting a similar strategy for unittest.
py.test does not currently integrate well with doctest; however, that will
likely
be the next feature to be added (per holger's talk at PyCon).
For output, unittest's TextTestRunner produces good looking, succinct output
on successful tests. For failed tests, it is not bad either. In contrast,
py.test
output is more highly formatted and voluminous -- it takes a while to get used
to.
unittest users have to adapt to the internal structure of the unittest module
and
become familiar with its class structure (test fixture, test case, test suite,
and test
runner objects). py.test does a good job of hiding its implementation.
py.test is relatively new and is continuing to evolve. Support tools like a
GUI test runner are just emerging. In contrast, unittest is based on a proven
model and the code is mature.
unittest module updates come up in distinct releases, often months or years
apart. py.test is subject to constant update by subversion. Personally, I like
the continuous updates, but it could be unsettling if you're depending on it
for production code.
Raymond Hettinger
Nigel Rowe>Have you seen Grig Gheorghiu's 3 part comparison of
unittest, and py.test?<
Very interesting articles, thank you. Testing seems something still in
quick development.
For small functions the doctests are useful, but py.test has some
advantages. Probably something even better that py.test can be
designed, taking some ideas from the doctests, or vice versa :-]
In py.test I see a couple of features useful for the Python language
too:
The raises:
py.test.raises( NameError, "self.alist.sor t(int_compare)" )
py.test.raises( ValueError, self.alist.remo ve, 6)
(A try can probably do something similar)
And the improved error messages:
"When it encounters a failed assertion, py.test prints the lines [3-4
lines?] in the method containing the assertion, up to and including the
failure. It also prints the actual and the expected values involved in
the failed assertion." http://agiletesting.blogspot.com/200...test-tool.html
Such things can help avoid (just for simple situations/functions!)
testing frameworks in the first place, so you can use just the normal
Python code to test other code.
Bye,
Bearophile
In my mind, practicing TDD is what matters most. Which framework you
choose is a function of your actual needs. The fact that there are 3 of
them doesn't really bother me. I think it's better to have a choice
from a small number of frameworks rather than have no choice or have a
single choice that might not be the best for your specific environment
-- provided of course that this doesn't evolve into a PyWebOff-like
nightmare :-)
Grig
[Roy Smith <ro*@panix.co m>] One thing that worries me a little is that all three seem to have advantages and disadvantages, yet none is so obviously better than the others that it stands out as the only reasonable way to do it. This means some groups will adopt one, some will adopt another, and the world will become fragmented.
Worry is a natural thing for someone with "panix" in their email address ;-)
FWIW, the evolution of py.test is to also work seemlessly with existing tests
from the unittest module.
the world diversifies, the world congeals,
Raymond Hettinger
On Fri, 01 Apr 2005 16:42:30 +0000, Raymond Hettinger wrote: FWIW, the evolution of py.test is to also work seemlessly with existing tests from the unittest module.
Is this true now, or is this planned?
I read(/skimmed) the docs for py.test when you linked to the project, but
I don't recall seeing that. Certainly some of the features made me drool
but I have an investment in unittest. If I can relatively easily port them
over, I'd love to use py.test. (I don't care about a small per-file
change, it'd probably be one I can automate anyhow. But I can't afford to
re-write every test.) I didn't see anything like this in the docs, but I
may have missed it.
That'd be cool.
>From what I know, the PyPy guys already have a unittest-to-py.test
translator working, but they didn't check in the code yet. You can send
an email to py-dev at codespeak.net and let them know you're interested
in this functionality.
Grig
Grig Gheorghiu wrote: In my mind, practicing TDD is what matters most. Which framework you choose is a function of your actual needs. The fact that there are 3 of them doesn't really bother me. I think it's better to have a choice from a small number of frameworks rather than have no choice or have a single choice that might not be the best for your specific environment -- provided of course that this doesn't evolve into a PyWebOff-like nightmare :-)
Grig
Grig,
Many thanks for your helpful essays.
unittest seems rather heavy. I don't like mixing tests with
documentation, it gives the whole thing a cluttered look.
Py.test is the more appealing but it doesn't appear to be
ready for packaging yet.
Thanks,
Colin W. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will Stuyvesant |
last post by:
I have a unittest testfile like this:
----------------------- test_mod.py ---------------------
import sys
sys.path.append('..')
import unittest
import mod
class Test_rmlutils(unittest.TestCase):
|
by: JAWS |
last post by:
I get this error message when trying to run a unittest test with a
dynamically created test method:
Traceback (most recent call last):
File "unittest.py", line 215, in __call__
testMethod()
TypeError: ?() takes no arguments (1 given)
I have no clue as to where the 1 given argument comes from...
|
by: Remy Blank |
last post by:
Ok, here we go.
I added the possibility for tests using the unittest.py framework
to be skipped. Basically, I added two methods to TestCase:
TestCase.skip(msg): skips unconditionally
TestCase.skipIf(expr, msg): skips if expr is true
These can be called either in setUp() or in the test methods. I also
added reporting of skipped tests to TestResult, _TextTestResult and
|
by: Jorgen Grahn |
last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so
on. All of these use the simplest possible internal layout: a number of
classes containing test*() methods, and the good old lines at the end:
if __name__ == "__main__":
unittest.main()
This is great, because each of the modules are runnable, and I can select
classes or tests to run on the commandline if I want to. However, running
all the tests from e.g. a...
|
by: paul kölle |
last post by:
hi all,
I noticed that setUp() and tearDown() is run before and after *earch*
test* method in my TestCase subclasses. I'd like to run them *once* for
each TestCase subclass. How do I do that.
thanks
paul
| |
by: David Vincent |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hello
I'm hoping to get some insight into a situation that seems odd to me.
My Python experience is limited; I've just started using the unittest
module. I've had some experience with unit test support in other
languages.
|
by: Oleg Paraschenko |
last post by:
Hello,
I decided to re-use functionality of "unittest" module for my purposes.
More precisely, I have a list of folders. For each folder, code should
enter to the folder, execute a command and assert the output. It's
reasonable to use "unittest" here, but the problem is that "unittest"
doesn't support (== I haven't found how) dynamic creation of tests.
I thought it would be very easy, but due to lack of closures in Python
(more...
|
by: Chris Fonnesbeck |
last post by:
I have built the following unit test, observing the examples laid out
in the python docs:
class testMCMC(unittest.TestCase):
def setUp(self):
# Create an instance of the sampler
self.sampler = DisasterSampler()
|
by: Chris Fonnesbeck |
last post by:
I have a module for which I am trying to code a unit test. However,
when I run unittest.main(), I get:
In : import PyMC
In : PyMC.unittest.main()
----------------------------------------------------------------------
Ran 0 tests in 0.000s
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |