Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python nosetests skip certain Tests

I am working on tests for a web application written in python.

Suppose I have 5 tests in my test_login.py module.

Every single test is a Class.

There is often one, base test that extends TestFlow class, which is our predefined test class.

And then other tests in this module extend that base test.

For instance :

#The base test 

TestLogin(TestFlow):
    #do login_test_stuff_here

#Another test in the same module

TestAccountDetails(TestLogin)
    #do account_details_test_stuff_here

...

It's actually quite handy, because in order to test for example AccountDetails user has to be logged in, so I can just inherit from TestLogin test and I am ready to test other functionality as a logged user.

All tests are in Project/project/tests folder.

We use nosetests with option --with-pylons to run tests.

And my question is if there is a way to mark certain TestClass as "Do not test this one".

Because I don't want to waste time to execute these "base tests" directly, because they will be execute by other tests that iherit from them.

There will be probably tones of these tests and I want to save every single second where it is possible.

I've already found something like Skip, SkipTest or @nottest, but these only work for test_methods within a ceratin TestClass, so I don't think it will work here, were I have a single class for each test case.

like image 323
koleS Avatar asked Aug 17 '12 13:08

koleS


2 Answers

Form nosetests it can be done as below by specifying the attributes http://nose.readthedocs.org/en/latest/plugins/attrib.html

Oftentimes when testing you will want to select tests based on criteria rather than simply by filename. For example, you might want to run all tests except for the slow ones. You can do this with the Attribute selector plugin by setting attributes on your test methods. Here is an example:

def test_big_download():
    import urllib
    # commence slowness...

test_big_download.slow = 1

Once you’ve assigned an attribute slow = 1 you can exclude that test and all other tests having the slow attribute by running

$ nosetests -a '!slow'
like image 190
vinay polisetti Avatar answered Oct 21 '22 06:10

vinay polisetti


You CAN actually use the skiptest for Classes too.

import unittest

@unittest.skip("Class disabled")
class TestLogin(TestFlow):
    ...
like image 5
Kashif Siddiqui Avatar answered Oct 21 '22 07:10

Kashif Siddiqui