Search code examples
pythonunit-testingtest-suite

Custom Python test suite not filtering and running all cases


I created a custom test suite to run only one of the test cases but all the test cases are being ran.

class TestBlackboxGame(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.public_path = os.path.join('public', 'index.html')
        cls.game_path = os.path.abspath(os.path.join('..', cls.public_path))
        assert(os.path.exists(cls.game_path))

        cls.driver = webdriver.Chrome()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def test_open_game(self):
        print('Visiting game at ' + self.game_path)
        self.driver.get(self.game_path)
        self.assertTrue('Wheel' == self.driver.title)

    def test_selenium_start_with_bing(self):
        self.driver.get("http://www.bing.com")    
        inputElement = self.driver.find_element_by_name("q")
        inputElement.send_keys("cheese!")
        inputElement.submit()
        self.assertTrue('cheese' in self.driver.title)

def testsuite_open_game():
    suite = unittest.TestSuite()
    suite.addTest(TestBlackboxGame("test_open_game"))
    return suite

if __name__ == '__main__':
    runner = unittest.TextTestRunner(failfast=True)
    runner.run(testsuite_open_game())

In my suite I only added the test case "test_open_game" but it is running both cases including going to Bing and searching. What am I missing?


Solution

  • It turns out that the code was doing what it is suppose to do. I am using Pycharm and didn't notice that Pycharm was running the script as Unittests. When Pycharm run this script it bypasses my main and run all the test cases regardless.