How to define an installation method that is called only once during testing with nosetest?

I run a couple of nosetests with test cases in different modules (files), each of which contains different tests.

I want to define a function / method that is called only once at runtime using nosetest .

I looked at the documentation (and, for example, here ), and see if there are methods like setup_module , etc. - but where and how to use them? Put them in my __init__.py ? Something other?

I tried using the following:

 class TestSuite(basicsuite.BasicSuite): def setup_module(self): print("MODULE") ... 

but this listing is never executed when I run the test using nosetest . I also do not get from unittest.TestCase (which will lead to errors).

+5
source share
2 answers

When viewing the package level, you can define a function called setup in __init__.py this package. By calling the tests in this package, the setup function in __init__.py is called once.

Setup Example

 - package - __init__.py - test1.py - test2.py 

See the documentation in the Test Packages section of the documentation .

+9
source

Try this one

 from nose import with_setup def my_setup_function(): print ("my_setup_function") def my_teardown_function(): print ("my_teardown_function") @with_setup(my_setup_function, my_teardown_function) def test_my_cool_test(): assert my_function() == 'expected_result' 

Holp helps ^^

+1
source

Source: https://habr.com/ru/post/1273881/


All Articles