Tuesday, February 22, 2011

Django-nose and Python nose

The most complete documentation about Python nose appears to be located here:
http://somethingaboutorange.com/mrl/projects/nose/1.0.0/writing_tests.html

Python nose uses auto-discovery by doing a regular expression using the testMatch pattern:

As with py.test, nose tests need not be subclasses of unittest.TestCase. Any function or class that matches the configured testMatch regular expression ((?:^|[\\b_\\.-])[Tt]est) by default – that is, has test or Test at a word boundary or following a - or _) and lives in a module that also matches that expression will be run as a test. For the sake of compatibility with legacy unittest test cases, nose will also load tests from unittest.TestCase subclasses just like unittest does. Like py.test, nose runs functional tests in the order in which they appear in the module file. TestCase-derived tests and other test classes are run in alphabetical order.
Within nose/config.py, this testMatch is defined here:
self.testMatch = re.compile(r'(?:^|[\\b_\\.%s-])[Tt]est' % os.sep) 

We can either override by invoking nose with the --testmatch parameter:
)
        parser.add_option(
            "-m", "--match", "--testmatch", action="store",
            dest="testMatch", metavar="REGEX",
            help="Files, directories, function names, and class names "
            "that match this regular expression are considered tests.  "
            "Default: %s [NOSE_TESTMATCH]" % self.testMatchPat,
            default=self.testMatchPat)

The Django nose runner also allows us to set the configuration by setting things as the environment variable too (NOSE_TESTMATCH):

config = nose.core.Config(env=os.environ, files=cfg_files, plugins=manager)

No comments:

Post a Comment