我試圖在另一個.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
具有以下格式:
class TestPageErrorSection(unittest.TestCase):
"""
"""
browser = None
site_url = None
def setUp(self):
global SITE_URL, BROWSER
if not BROWSER:
BROWSER = self.browser
if not SITE_URL:
SITE_URL = self.site_url
BROWSER.open(SITE_URL)
BROWSER.window_maximize()
print 'page not found 404 error'
self._pageerror_section = ErrorSection(BROWSER)
def _primary_navigation(self):
# I want to call test_check_footer_visible here.
我Call Class Method From Another Class
不完全 - 它可以通過'FooterSection.test_check_footer_visible.im_func(self)'成爲可能,但它會是非常糟糕的風格 - 有兩個原因:1.因爲它是不好的風格,因爲被調用者旨在從完全不同的階級中獲得「自我」。但它會工作。這只是爲了完整性。 – glglgl
@glglgl - 是的,我想這會奏效。這樣做有點扭曲。從本質上講,這是一個非常可疑的方式實施#2我想...... – mgilson
是的。本質上,它解除了將函數作爲方法所做的過程...'FooterSection .__ dict __ ['test_check_footer_visible'](self)'也可以,但現在變得很奇怪。 – glglgl