TDD with nose or py.test

L

Lacrima

Hello!

I am learning TDD with Python and there is not much information about
this topic. Python is shipped with unittest module. That is fine, but
I also discovered other libraries: nose and py.test. They promise to
make life yet easier for a developer. But I still can't figure out,
which combination I should use them in.
Nose seems simpler than py.test, but py.test offers more features. And
both py.test and nose say that they do not replace unittest module,
but extend it.
So as I understand my choice should be nose + unittest, or py.test +
unittest.
And now I'd like to hear about best practices in TDD in Python. Maybe
not best practices, but basic approach.
So which tests should I write with unittest, which with nose or
py.test? How should I combine them?

I am learning Python and I need your advice.
Thanks in advance.

Sorry if my English isn't very proper
 
A

Aahz

I am learning TDD with Python and there is not much information about
this topic. Python is shipped with unittest module. That is fine, but
I also discovered other libraries: nose and py.test. They promise to
make life yet easier for a developer. But I still can't figure out,
which combination I should use them in.

My company decided to use py.test because it offered better support for
cross-platform and multi-machine testing (at least as of a couple of
months ago when we made the decision). Otherwise, the two seem pretty
comparable and nose seems to be easier to use.
 
R

Roy Smith

Lacrima said:
Hello!

I am learning TDD with Python and there is not much information about
this topic. Python is shipped with unittest module. That is fine, but
I also discovered other libraries: nose and py.test. They promise to
make life yet easier for a developer. But I still can't figure out,
which combination I should use them in.
Nose seems simpler than py.test, but py.test offers more features. And
both py.test and nose say that they do not replace unittest module,
but extend it.
So as I understand my choice should be nose + unittest, or py.test +
unittest.
And now I'd like to hear about best practices in TDD in Python. Maybe
not best practices, but basic approach.
So which tests should I write with unittest, which with nose or
py.test? How should I combine them?

You're obsessing over details. Pick one and go with it. I've been using
unittest for years and I'm mostly happy with it. I've played with py.test
a bit, and while I like some features, I keep finding myself wandering back
to unittest. Maybe it's just what I know so I'm comfortable with it.

I've glanced at nose, but every time I look at it, I ask myself, "Do I want
to learn another testing tool, or do I just want to get on with testing the
code I'm writing now?", which inevitably brings me back to just sticking
with unittest.

I am very much a fan of TDD. Whenever I write a new class, here's the
first test I write:

class TestFoo(unitest.TestCase):
def test_construct(self):
foo = Foo()

If that passes, it means I've managed to create a new class, register it
with my build system (and, most likely, my source control system). In
keeping with the "write the very smallest amount of code you need to make
your test pass", my class will usually look like this at the point the
above test first passes:

class Foo:
pass

After that, it's all about adding features :)
 
G

geremy condra

Hello!

I am learning TDD with Python and there is not much information about
this topic. Python is shipped with unittest module. That is fine, but
I also discovered other libraries: nose and py.test. They promise to
make life yet easier for a developer. But I still can't figure out,
which combination I should use them in.
Nose seems simpler than py.test, but py.test offers more features. And
both py.test and nose say that they do not replace unittest module,
but extend it.
So as I understand my choice should be nose + unittest, or py.test +
unittest.
And now I'd like to hear about best practices in TDD in Python. Maybe
not best practices, but basic approach.
So which tests should I write with unittest, which with nose or
py.test? How should I combine them?

I am learning Python and I need your advice.
Thanks in advance.

Sorry if my English isn't very proper

I use unittest, but mostly because its so close to junit and cppunit,
which I also use extensively. Having said that, it *is* in the standard
library and is a common denominator between all your options.

Geremy Condra
 
P

Paul Rubin

geremy condra said:
I use unittest, but mostly because its so close to junit and cppunit,
which I also use extensively. Having said that, it *is* in the standard
library and is a common denominator between all your options.

What happened to doctest?
 
G

geremy condra

What happened to doctest?

Worth mentioning as an option, I suppose, but at least for me
unittest fits the TDD workflow better. YMMV, of course.

Geremy Condra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top