我试图在另一个.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