0

I am running a a selenium functional test using nose from inside a django function using:

arg = sys.argv[:1]
arg.append('--verbosity=2')
arg.append('-v')
out = nose.run(module=ft1.testy1, argv=arg, exit=False)

I have created the functional test using the selenium IDE. Part of the test looks like:

class y1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.yahoo.com/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_y1(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element_by_link_text("Weather").click()
        driver.save_screenshot('out1.png')
        return " this is a returned value"

I want to return a string value (" this is a returned value") to the calling function. How can I do this?

1 Answer 1

1

The output of your nose.run() does not correspond to your test method. The default behavior for unittest.TestCase is to throw an exception. If you would like to signal an external code some specific detail, you can always do it through global/class variables, files, etc.

For example, this is how to do it with a class variable (results)

ft1_runner.py:

import nose

import ft1_test

if __name__ == '__main__':
    out = nose.run(module=ft1_test, exit=False)
    print 'Y1.test_y1 test results returned:', ft1_test.Y1.results['test_y1']

ft1_test.py:

import unittest

class Y1(unittest.TestCase):
    results = {}

    def test_y1(self):
        Y1.results['test_y1'] = "this is a returned value"

I think it would help if you can describe the problem you are trying to solve: this seems a little awkward and error prone (what if the test is called twice, or test skipped, etc.)

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for looking at this Oleksiy. I'm pretty new to python so could I ask for more detail on how you would do this, Lets say I want to make the string " this is a returned value" available to the calling function.
added a code example, but it would be helpful to see the actual problem you are trying to solve.
Thanks, that helps. I assume "results = {}" would be a global variable?
Yes, anyone referring to Y1 class will be able to see the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.