TDD with nose or py.test

Discussion in 'Python' started by Lacrima, Nov 30, 2009.

  1. Lacrima

    Lacrima Guest

    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
    Lacrima, Nov 30, 2009
    #1
    1. Advertising

  2. Lacrima

    Aahz Guest

    In article <>,
    Lacrima <> wrote:
    >
    >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.
    --
    Aahz () <*> http://www.pythoncraft.com/

    The best way to get information on Usenet is not to ask a question, but
    to post the wrong information.
    Aahz, Dec 5, 2009
    #2
    1. Advertising

  3. Lacrima

    Roy Smith Guest

    In article
    <>,
    Lacrima <> wrote:

    > 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 :)
    Roy Smith, Dec 5, 2009
    #3
  4. On Mon, Nov 30, 2009 at 8:46 AM, Lacrima <> wrote:
    > 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
    geremy condra, Dec 5, 2009
    #4
  5. Lacrima

    Paul Rubin Guest

    geremy condra <> writes:
    > 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?
    Paul Rubin, Dec 5, 2009
    #5
  6. On Sat, Dec 5, 2009 at 6:37 PM, Paul Rubin <> wrote:
    > geremy condra <> writes:
    >> 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?


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

    Geremy Condra
    geremy condra, Dec 6, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer
    Replies:
    3
    Views:
    382
    Chris Mahoney
    Jul 13, 2003
  2. Phlip
    Replies:
    0
    Views:
    407
    Phlip
    Aug 2, 2004
  3. Alexander Eisenhuth

    C++ test framework for TDD

    Alexander Eisenhuth, Nov 16, 2005, in forum: C++
    Replies:
    3
    Views:
    352
    Dave Steffen
    Nov 16, 2005
  4. Roald
    Replies:
    1
    Views:
    106
    R. Osinga
    Feb 2, 2013
  5. Hareesha Karunakar

    python nose unit test - test plan preparation

    Hareesha Karunakar, Apr 2, 2014, in forum: Python
    Replies:
    2
    Views:
    34
    Mark Lawrence
    Apr 3, 2014
Loading...

Share This Page