Unit testing frameworks

G

grkuntzmd

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
 
M

Maxim Khitrov

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
 
P

pruebauno

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
 
F

Fabio Zadrozny

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
 
G

grkuntzmd

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?
 
F

Fabio Zadrozny

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
 
A

Alexander Draeger

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
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top