Вопрос

I'm using nose.

My current code is:

class A():
    def __init__():
        pass
    def do_somthing(self):
        do_it

class Test(unittest.TestCase):
    def setUp(self):
        self.a = A()
    def testSomthing:
        raise assert(self.a.do_something())

I don't want to create an instance of A class each test, I want to create it only once. How can i do that?

Это было полезно?

Решение

You could use setUpClass, see the documentation:

A class method called before tests in an individual class run. setUpClass is called with the class as the only argument and must be decorated as a classmethod():

@classmethod
def setUpClass(cls):
    ...
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top