我试图在另一个.py
文件中调用test_check_footer_visible
。在
origin.py
具有:
class FooterSection(unittest.TestCase):
"""
"""
browser = None
site_url = None
def setUp(self):
self.browser.open(self.site_url)
self.browser.window_maximize()
# make footer section
self._footer = FooterPage(self.browser)
def test_check_footer_visible(self):
#press the page down
self.browser.key_down_native("34")
self.browser.key_down_native("34")
self.browser.key_down_native("34")
print "Page down"
time.sleep (10)
现在在dest.py
我需要给test_check_footer_visible()
打电话。我该怎么做?在
dest.py
具有以下格式:
我尝试了Call Class Method From Another Class中的所有内容
你不能(如果不做一些不光彩的事情,请看@glglglglglglglgl的注释),至少在不改变代码的情况下。不能这样做的原因是
test_check_footer_visible
将断言传入的第一个元素是FooterSection
类的实例(它不是TestPageErrorSection
的实例)。你有(至少)几个选择的重新因素。在1)使
TestPageErrorSection
从FooterSection
继承并直接使用该函数(例如self.test_check_footer_visible()
基于类名,这似乎不是一个很好的选择2)使
test_check_footer_visible()
成为正则函数。然后可以从任何一个类调用它。在3)创建第三个类(例如
SectionBase
),将test_check_footer_visible
放在该类上,并让其他2个类从中继承。在相关问题 更多 >
编程相关推荐