Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nose test single setup function called once

How do I create a single setup function all my nose test cases that is only called once during initialization? I have a global configuration that only needs to be set once and I feel that adding the following to each module (even calling a setup function for each module) is a bit superfluous:

def setUp(self):
    Configuration.configure('some configuration settings')
like image 469
Vincent Catalano Avatar asked May 18 '13 07:05

Vincent Catalano


People also ask

Which command is used to run nose tests?

nose can be integrated with DocTest by using with-doctest option in athe bove command line. The result will be true if the test run is successful, or false if it fails or raises an uncaught exception. nose supports fixtures (setup and teardown methods) at the package, module, class, and test level.

What is Nose tools?

The nose. tools module provides a number of testing aids that you may find useful, including decorators for restricting test execution time and testing for exceptions, and all of the same assertX methods found in unittest.

What is Nose framework?

Nose is a popular test automation framework in Python that extends unittest to make testing easier. The other advantages of using the Nose framework are the enablement of auto discovery of test cases and documentation collection.


1 Answers

I figured it out! Nose provides package-level setup and teardown as documented here. All I have to do is define the setup method in the package's __init__.py file.

Here, you can see an example of how to use the setup function. To make things simple:

lines = []
def setup():
    global lines
    lines.append('test') # here, we can trigger a build
                         # and read in a file, for example

def test_this():
    assert lines[0] == 'test'
like image 132
Vincent Catalano Avatar answered Oct 09 '22 17:10

Vincent Catalano