0

I have trouble running my test case from a unit test suite. The problem is that I am defining driver in a setup-metod and not in the test it self. My code is following

the suite:

import unittest
from pobocky import TestPobocky_D


def suite():
    suite = unittest.TestSuite()
    #suite.addTest(TestPobocky_D("setup_method"))
    suite.addTest(TestPobocky_D('test_pobocky_D'))
    return suite

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite())

The test_pobocky_D looks like this

class TestPobocky_D(unittest.TestCase):
    def setup_method(self, method):
        self.driver = webdriver.Chrome(ChromeDriverManager().install())
        self.vars = {}

    def teardown_method(self, method):
        self.driver.quit()


    def test_pobocky_D(self):

        self.driver.get(URL_pobocky)
        acceptConsent(self.driver)
        self.driver.maximize_window()
        ... test

the error I get is : AttributeError: 'TestPobocky_D' object has no attribute 'driver' Can somehow help me how to solve that please ? How can I include the setup_method in the runner so it works? If I put the definition of driver into test_pobocky_D it works but I need the setup metod cuz I will most likely be using remote driver in the future and changing it will be easier that way.

Thanks in advance for any ideas or help

KDK
  • 57
  • 6
  • 1
    Do you use some plugin/add-on that supports `setup_method`/`teardown_method`? The standard `unittest` methods are called `setUp` and `tearDown`. – MrBean Bremen Feb 25 '22 at 17:55
  • I feel so stupid about that question haha. btw @MrBeanBremen if you want you can post it as an answer and I can confirm it if you care about it :) cheers – KDK Feb 26 '22 at 13:07
  • 1
    If you feel stupid about the question, you can just delete it :) Though there are no stupid questions, only stupid answers... Glad to have helped, but I doubt an answer would help anyone else. – MrBean Bremen Feb 26 '22 at 15:37

0 Answers0