Skip to content

use setUpClass&tearDownClass #1240

Answered by mdmintz
c350147221 asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to customize setUp() and tearDown(), do it like this:

https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py

Example:

from seleniumbase import BaseCase

class BaseTestCase(BaseCase):
    def setUp(self):
        super(BaseTestCase, self).setUp()
        # <<< Run custom setUp() code for tests AFTER the super().setUp() >>>

    def tearDown(self):
        self.save_teardown_screenshot()
        if self.has_exception():
            # <<< Run custom code if the test failed. >>>
            pass
        else:
            # <<< Run custom code if the test passed. >>>
            pass
        # (Wrap unreliable tearDown() code in a try/excep…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

You must be logged in to vote
1 reply
@mdmintz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants