Ask Your Question

How to add new test cases to TEMPEST Test suite

asked 2013-12-16 10:19:52 -0500

vinayd gravatar image

updated 2013-12-18 14:29:29 -0500

larsks gravatar image


I have some test cases to my project specific, wanted to use TEMPEST to run those tests on cinder API's, now i searched every where on google, i got very little documentation on adding new tests to TEMPEST.

Following Lars's suggestion, I tried this:

  1. Created an Folder named Mycode parallel to tempest folder and other files like README.rst.
  2. added an under it.
  3. Now i created an .py file with below code block

    #!/usr/bin/env python 
    import Mycode 
    import sys 
    import os 
    print "This is system path " 
    def func1(): 
        print "This is vinay here positive case" 
        assert (True) 
    def func2(): 
      print "This is vinay here negative case failed" 
      assert (Fail)
  4. Now when i execute the test "nosetests", its throwing error as below:

    ERROR: Failure: ImportError (No module named Mycode)
    Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/nose/", line 364, in loadTestsFromName addr.filename, please help
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-12-16 13:19:36 -0500

larsks gravatar image

updated 2013-12-18 14:34:22 -0500

Tempest uses the "nose" testing framework for Python; you can all about it here. Here's a quick example:

Let's assume we're going to be writing tests for something called "myproject". We'll start by creating a new myproject package in the top-level tempest directory:

mkdir myproject
touch myproject/

Now we're going to add a module call

vim myproject/

Inside this file will be a simple test:

def test_something_that_works():

def test_something_that_fails():

Now I can run just these tests by running, from the top-level directory:

$ nosetests myproject

Which will result in:

myproject.test_myproject.test_something_that_works ... ok
myproject.test_myproject.test_something_that_fails ... FAIL

FAIL: myproject.test_myproject.test_something_that_fails
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/", line 197, in runTest
  File "/home/lkellogg/src/tempest/myproject/", line 7, in test_something_that_fails

Ran 2 tests in 0.001s

FAILED (failures=1)

These tests would also run automatically if you were to run the script or tox. Note that the tempest framework can use various attributes to determine which tests are run. For example, you can elect to run only "smoke tests", which are identified in the Tempest code base like this:

from tempest.test import attr

def a_simple_test():

You'll note that the actual tests are usually a little more complex than what I've shown here, and may include setup/teardown code. Look through the existing tests for examples, and read through the Nose documentation to understand how everything works.

Tempest actually uses the tox framework to run the tests; this ensure that everything runs using a Python virtualenv for packages, and makes it easy to select among different groups of tests. For example, to run just the "smoke" tests:

$ tox smoke

Or just the pep8 tests:

$ tox pep8

I hope this helps you get started.


Looking at your first attempt, there are several issues you need to address:

  1. The argument to nosetests needs to be a package or module name (so, for example, nosetests Mycode.
  2. Your tests need to be named test_something (so, for example, test_func1 and test_func2).
  3. Your module needs to be named test_something also (e.g., in my example it was called test_myproject).
  4. Your package appears to be trying to import itself, which is a little unusual.

Before trying again, you should probably spend some time reading the Nosetest documentation, which explains how all of this works and includes a number of examples.

edit flag offensive delete link more


Thanks a lot for your quick suggestion, this really helps, only thing i wanted to know is that, your saying that add your project at toplevel tempest directly, which is that top-level directory your are talking about, for example if my directory is "C:\RMC\Tempest_code\temptest_working\tempest\", in these there are parallel folders such as "api","cli","Commom" etc, so need to add my folder here.....?

vinayd gravatar imagevinayd ( 2013-12-16 22:37:17 -0500 )edit

It should be the directory containing the "README.rst" file, the "tox.ini" file, the "" script, etc.

larsks gravatar imagelarsks ( 2013-12-16 22:39:24 -0500 )edit

I should also note that it only makes sense to add your tests here if you expect to run them *along with all the other temptest tests*. If you expect to always run your tests independently there's no particular reason to colocate them with the tempest source.

larsks gravatar imagelarsks ( 2013-12-16 22:40:49 -0500 )edit

Thanks a lot larsks for your suggestion, i have another question, if we want to reuse some of the python classes such as "" in my test case execution, as i have to make some REST calls, is that ok to import those classes in my project namespace or what do u suggest...?

vinayd gravatar imagevinayd ( 2013-12-16 23:43:44 -0500 )edit

I think that's fine.

larsks gravatar imagelarsks ( 2013-12-17 08:25:45 -0500 )edit

answered 2013-12-19 03:33:08 -0500

darragh-oreilly gravatar image

This is a good guide.

edit flag offensive delete link more


Note that this guide is slightly outdated. Not everything in there is still up-to-date.

rahmu gravatar imagerahmu ( 2014-02-21 08:27:41 -0500 )edit

Thanks a lot for the informative and helpful post. We have written UTs and FTs for our new service say 'abc' These tests are present at /opt/stack/abc/abc/tests/functional and /opt/stack/abc/abc/tests/unit We need to run these testcases as part of tempest now !

So, we have copied our test cases at /opt/stack/tempest/tempest/tests/abc and we are trying to execute the same from nossetests. nosetest is not considering our testcases, can you please guide us here ! Yes, we have also tried to keep the same under /opt/stack/tempest/tempest/tests/cli and execute but still no use. On a liter note, please let us know, how to disable the pylint kind of errors or warnings Thanks a lot for your patience

drajsingh2304 gravatar imagedrajsingh2304 ( 2014-07-08 15:14:29 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools



Asked: 2013-12-16 10:19:52 -0500

Seen: 1,732 times

Last updated: Dec 19 '13