How To Fix "TypeError: 'NoneType' object is not callable"

3.5k views Asked by At

When I run my script:

from selenium import webdriver
# from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import os
import pytest
import unittest
from nose_parameterized import parameterized

    class multiBrowsers(unittest.TestCase):
        @parameterized.expand([
            ("chrome"),
            ("firefox"),
        ])

        def setUp(self, browser):

            if browser == "firefox":
                caps = DesiredCapabilities.FIREFOX
                caps["marionette"] = True
                caps["binary"] = "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
                self.driver = webdriver.Firefox(capabilities=caps)
            elif browser == "chrome":
                self.driver = webdriver.Chrome()

        def test_loadPage(self):
            driver = self.driver
            driver.get("http://www.google.com")

        def tearDown(self):
            self.driver.quit()

I get the error:

Error
TypeError: 'NoneType' object is not callable

I read that I am not passing something correctly but I don't know where to look. Thanks in advance for the help!

3

There are 3 answers

0
Nikita Vikhe On

I was getting the same error while using parametrized.expand with unittest.TestCase class. While building suit parametrized adds suffices to tests _0, _1 and so if you are adding tests manually into suite it throws this error. Best solution is to use,

suite = unittest.TestSuite()
testloader = unittest.TestLoader()
testnames = testloader.getTestCaseNames(t_class)
for name in testnames:
    suite.addTest(t_class(name))
runner = unittest.TextTestRunner(verbosity=2)
3
Levi Noecker On

Total guess, but I think this might be your problem:

@parameterized.expand([
    ("chrome"),
    ("firefox"),
])

Something in @parameterized might not be recognizing those as tuples. Try adding a comma to make them explicitly tuples:

@parameterized.expand([
    ("chrome", ),
    ("firefox", ),
])
0
elm On

Not sure if parameterized can be applied to setUp, I managed to get it working with test function:

@parameterized.expand([
    ("chrome"),
    ("firefox"),
])
def test_loadPage(self, browser):

After adding @parametrized decorator I was getting 'NoneType' object is not callable error and test name was not displayed correctly in Test Explorer.

After refreshing methods in Test Explorer test name got formatted to test_loadPage_0_chrome and test worked.