functional testing - Call a method from inside another class in Python -


i have python tests run nose. example this:

class logout(unittest.testcase):      def report_pass_fail(self):         #code      def setup(self):         #code      def test_logout(self):         #code      def teardown(self):         #code 

because have big amount of tests , because want create modular code architecture....i have report_pass_fail , setup , teardown methods inside separate file(module) , call them when needed inside test's class.

i not experienced in oop .i tried several combinations no success. how that?

the module created this:

import json, httplib, base64, unittest, sys selenium import webdriver import classname creds import config, sauce_hub  class fixtures(unittest.testcase):     def report_pass_fail(self):         base64string = base64.encodestring('%s:%s' % (config['username'], config['access-key']))[:-1]         result = json.dumps({'public': 'true', 'passed': sys.exc_info() == (none, none, none)})         connection = httplib.httpconnection("saucelabs.com")         connection.request('put', '/rest/v1/%s/jobs/%s' % (config['username'], self.wd.session_id), result, headers={"authorization": "basic %s" % base64string})         result = connection.getresponse()         return result.status == 200      def setup(self):         desired_capabilities = webdriver.desiredcapabilities.firefox         desired_capabilities['version'] = '4'         desired_capabilities['platform'] = 'linux'         desired_capabilities['name'] = classname.getname(self)         desired_capabilities['record-video'] = false          self.wd = webdriver.remote(desired_capabilities=desired_capabilities,                                    command_executor="http://" + config['username'] + ":" + config['access-key'] + sauce_hub)         self.wd.implicitly_wait(10)      def teardown(self):         self.wd.quit() 

and use in test file this:

import unittest fixture_module import fixtures #is_alert_present(wd)  #credentials    class deletelecturefromcoursepanel(fixtures,unittest.testcase):      import fixture_module      f = fixture_module.fixtures()     f.report_pass_fail()      f.setup()      def test_deletelecturefromcoursepanel(self):         success = true         wd = self.wd         wd.find_element_by_link_text("delete").click()         self.assertequal("are sure?", wd.switch_to_alert().text)         wd.switch_to_alert().accept()         self.asserttrue(success)      f.teardown()   if __name__ == '__main__':     unittest.main() 

it seems ok , there no errors in pycharmide when run console says :

valueerror:no such test method in <class 'fixture_module.fixtures'> : runtest 

you making much more complicated needs be. if deletelecturefromcoursepanel inherits fixtures, already gets methods defined in class. called automatically test runner, , there's no reason call them manually (especially within class body that).

there's no need additionally inherit testcase. via fixtures.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -