在python中使用一个testclass函数到另一个testclass

时间:2018-10-10 06:12:32

标签: python django

我在Django测试用例中有两个测试类。我想在Python中将一个testclass函数用于另一个testclass。 Django testcase用于restframework:

expression

如何在class TestExample(APITestCase): def test_ex(self): print "test_ex" class TestSample(APITestCase): def test_sample(self): print "test_sample" 函数中使用test_ex function

2 个答案:

答案 0 :(得分:0)

一种方法是继承

class TestExample(APITestCase):
  def test_ex(self):
  print "test_ex"

class TestSample(TestExample):
   def test_sample(self):
     print "test_sample"

答案 1 :(得分:0)

这里的解决方案是使用多重继承:首先使用要在测试用例之间共享的代码编写一个mixin类(从对象派生),然后从两个.expect(Selector('html').textContent).contains('learning_items'); (或子类的子类)继承的测试用例)和您的mixin:

Unittest.TestCase
相关问题