Unit testing frameworks

Discussion in 'Python' started by grkuntzmd@gmail.com, Mar 24, 2009.

  1. Guest

    I am looking for a unit testing framework for Python. I am aware of
    nose, but was wondering if there are any others that will
    automatically find and run all tests under a directory hierarchy.

    Thanks, Ralph
    , Mar 24, 2009
    #1
    1. Advertising

  2. On Tue, Mar 24, 2009 at 8:06 AM, <> wrote:
    > I am looking for a unit testing framework for Python. I am aware of
    > nose, but was wondering if there are any others that will
    > automatically find and run all tests under a directory hierarchy.


    Have you already looked at the unittest module? Below is the code I
    use for one of my current projects to load all test cases in package.
    This code is sitting in __init__.py, and the test cases are in
    separate files (util.py, util_threading.py, etc.). Those files can
    contain as many TestCase classes as needed, all are loaded with
    loadTestsFromModule. You could easily modify this code to
    automatically generate the modules list if you want to.

    # repo/pypaq/test/__init__.py
    from unittest import TestSuite, defaultTestLoader

    import logging
    import sys

    __all__ = ['all_tests']
    modules = ['util', 'util_buffer', 'util_event', 'util_threading']

    if not __debug__:
    raise RuntimeError('test suite must be executed in debug mode')

    all_tests = []

    for name in modules:
    module = __import__('pypaq.test', globals(), locals(), [name], 0)
    tests = defaultTestLoader.loadTestsFromModule(getattr(module, name))

    __all__.append(name)
    all_tests.append(tests)
    setattr(sys.modules[__name__], name, tests)

    logging.getLogger().setLevel(logging.INFO)
    all_tests = TestSuite(all_tests)

    I then have test_pypaq.py file under repo/, with which I can execute
    all_tests or only the tests from a specific module:

    # repo/test_pypaq.py
    from unittest import TextTestRunner
    from pypaq.test import *

    TextTestRunner(verbosity=2).run(all_tests)

    - Max
    Maxim Khitrov, Mar 24, 2009
    #2
    1. Advertising

  3. Guest

    On Mar 24, 8:06 am, wrote:
    > I am looking for a unit testing framework for Python. I am aware of
    > nose, but was wondering if there are any others that will
    > automatically find and run all tests under a directory hierarchy.
    >
    > Thanks, Ralph


    *Nose
    *Trial
    *py.test
    , Mar 24, 2009
    #3
  4. En Tue, 24 Mar 2009 09:06:47 -0300, <> escribió:

    > I am looking for a unit testing framework for Python. I am aware of
    > nose, but was wondering if there are any others that will
    > automatically find and run all tests under a directory hierarchy.


    All known testing tools (and some unknown too):

    http://pycheesecake.org/wiki/PythonTestingToolsTaxonomy

    --
    Gabriel Genellina
    Gabriel Genellina, Mar 24, 2009
    #4
  5. Hi Andew,

    > not exactly a framework, but useful while working on small projects - you
    > can run tests from inside eclipse (using the pydev plugin for python).
    > it's easy to run all tests or some small subset (although it is a bit
    > buggy for 3.0).


    What exactly is not working with 3.0? (couldn't find any related bug
    report on that).

    Cheers,

    Fabio
    Fabio Zadrozny, Mar 25, 2009
    #5
  6. Guest

    In unittest, has anyone used the *NIX command "find" to automatically
    build a test suite file of all tests under a specified directory?

    I generally name my tests as _Test_ORIGINAL_MODULE_NAME.py where
    ORIGINAL_MODULE_NAME is the obvious value. This way, I can include/
    exclude them from deployments, etc. in my Makefile based on filename
    patterns. I was thinking of doing something with "find" to get a list
    of test file names and then run them through a Python script to
    produce a top-level suite file, probably as the first step in my
    Makefile test target.

    Any thoughts?
    , Mar 25, 2009
    #6
  7. > sorry for not reporting a bug - i assumed you'd know (and the workarounds
    > described above meant i wasn't stalled).
    >
    > i also have eclipse 3.4.2 with pydev 1.4.4.2636 on a separate machine (ie
    > new versions), and i can try there if you want (it will take a while to
    > get the source there, but is not a problem).


    No need... I can probably reproduce it easily here. I've added the bug
    report (should be fixed for the next release:
    https://sourceforge.net/tracker/?func=detail&aid=2713178&group_id=85796&atid=577329
    )

    Cheers,

    Fabio
    Fabio Zadrozny, Mar 26, 2009
    #7
  8. Hi,

    I'm work on a testing framework for Python. Until now I have
    implemented the main features of PyUnit and JUnit 4.x. I like the
    annotation syntax of JUnit 4.x and it's theory concept is great
    therefore you can imagine how my framework will be.

    I plan a lot of additionally features which are neither part of Junit
    4.5 nor PyUnit. Finding testcases automatically is a good idea.

    Alex
    Alexander Draeger, Mar 29, 2009
    #8
    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. Phillip Lord

    Unit testing GUI, possible frameworks

    Phillip Lord, Mar 2, 2004, in forum: Java
    Replies:
    0
    Views:
    321
    Phillip Lord
    Mar 2, 2004
  2. John Maclean
    Replies:
    1
    Views:
    337
    Martin P. Hellwig
    Apr 13, 2010
  3. Ulrich Eckhardt

    unit-profiling, similar to unit-testing

    Ulrich Eckhardt, Nov 16, 2011, in forum: Python
    Replies:
    6
    Views:
    325
    Roy Smith
    Nov 18, 2011
  4. Sean O'Dell

    Unit Testing Without Frameworks

    Sean O'Dell, Jul 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    116
    Randy Lawrence
    Jul 11, 2004
  5. Bill Mosteller
    Replies:
    0
    Views:
    216
    Bill Mosteller
    Oct 22, 2009
Loading...

Share This Page