首页 > 解决方案 > 在python中使用一个testclass函数到另一个testclass

问题描述

我在 django testcases 中有两个测试类。我想在 python 中将一个 testclass 函数用于另一个 testclass。restframework 的 django 测试用例:

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

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

如何test_ex functiontest_sample函数中使用

标签: pythondjango

解决方案


一种方法是继承

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

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

推荐阅读