[TIP] Tag-based execution plugin for nose?

Kumar McMillan kumar.mcmillan at gmail.com
Tue Jun 24 10:38:39 PDT 2008


As of 0.10.3 (metaclass bugfix) you can create an abstract class for
your tests to specify attributes.  For example:

class UITestType(type):
    def __new__(cls, name, bases, dct):
        for key, val in dct.items():
            if key.startswith('test') and inspect.isfunction(val):
                # add a UI attribute
                dct[key].UI = True
        return type.__new__(cls, name, bases, dct)

class UITest(unittest.TestCase):
    """A User Interface test case"""
    __metaclass__ = UITestType

class TestLoginPage(UITest):
    def setUp(self):
        # setup twill or selenium, etc

    def test_user_can_login(self):
        # etc...

then from the command line:

$ nosetests -a UI

will run all tests that subclass UITest.


Unfortunately we didn't get around to adding a simple metaclass type
for this and documentation to point out this strategy.


K

On Tue, Jun 24, 2008 at 12:24 PM, C. Titus Brown <ctb at msu.edu> wrote:
> nosetests -a spam,cheese,crackers
>
> def test_me():
>   ...
> test_me.spam=True
> ...
>
> --t
>
> On Tue, Jun 24, 2008 at 01:04:15PM -0400, Jesse Noller wrote:
> -> Has anyone seen/used/made a tag-based test running for nose? I was
> -> thinking about going down the path of writing one so I figured I'd ask
> -> first :)
> ->
> -> I'm thinking about something like nosetests
> -> --tags="spam,cheese,crackers" which would then load all tests matching
> -> those tags. I was thinking about embedding the tags in a __tags__ = []
> -> attribute in each test.
> ->
> -> -jesse
> ->
> -> _______________________________________________
> -> testing-in-python mailing list
> -> testing-in-python at lists.idyll.org
> -> http://lists.idyll.org/listinfo/testing-in-python
>
> --
> C. Titus Brown, ctb at msu.edu
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>



More information about the testing-in-python mailing list