This is my tests class, in mymodule.foo
:
class Some TestClass(TestCase):
def setUpClass(cls):
# Do the setup for my tests
def test_Something(self)
# Test something
def test_AnotherThing(self)
# Test another thing
def test_DifferentStuff(self)
# Test another thing
I'm running the tests from Python with the following lines:
tests_to_run = ['mymodule.foo:test_AnotherThing', 'mymodule.foo:test_DifferentStuff']
result = nose.run(defaultTest= tests_to_run)
(This is obviously a bit more complicated and there's some logic to pick what tests I want to run)
Nose will run just the selected tests, as expected, but the setUpClass
will run once for every test in tests_to_run
. Is there any way to avoid this?
What I'm trying to achieve is to be able to run some dynamic set of tests while using nose
in a Python script (not from the command line)
As @jonrsharpe mentioned, setupModule
is what I was after: it will run just once per the whole module where my tests reside.