pythonpython-unittestnose2

nose2 with such DSL does not find tests


This might be really stupid, but I can't get it to work... I'm want to use the such DLS in nose2 with python 2.7 in Linux. I'm trying out the beginning of the example from the documentation http://nose2.readthedocs.org/en/latest/such_dsl.html (see code below) but it doesn't run the tests, no matter how I launch it from the command line.

My file is called test_something.py, it's the only file in the directory. I've tried running from the command line with >> nose2 and >> nose2 --plugin nose2.plugins.layers, but I always get Ran 0 tests in 0.000s. With >> nose2 --plugin layers I get ImportError: No module named layers.

How am I supposed to run this test from the command line?? Thanks!

Code below:

import unittest
from nose2.tools import such

with such.A("system with complex setup") as it:
    @it.has_setup
    def setup():
        print "Setup"
        it.things = [1]

    @it.has_teardown
    def teardown():
        print "Teardown"
        it.things = []

    @it.should("do something")
    def test():
        print "Test"
        assert it.things
        it.assertEqual(len(it.things), 1)

Solution

  • DOH! I forgot to add it.createTests(globals()) at the end of the file!