I'm using Python with Selenium and unittest. I have four tests in one class since they're all related unit tests. How do I have it skip the next test(s) if the preceding test fails? I've read up on all the documentation for unittest's skip methods, but none of it is exactly what I need. Is there a way to tell it to exit the class?
Here is a jist of what my code currently looks like:
def test_dealer_search_id_contains(self):
try:
LoginPage.login(self, ULV.AA_USERNAME, ULV.AA_PASSWORD)
except TimeoutException:
add_test_result(3, 5, "This test failed attempting to login with the user's credentials.")
add_test_result(4, 2, 'This test is blocked due to failure of a preceding test.')
self.fail(msg='Dealer: Search - Test failure.')
def test_dealer_search_id_exact(self):
code for this test here
How do I have it skip the remaining test or exit the class all together?
I appreciate any help that can be provided.
EDIT: I am using PyTest as my runner and I do have additional tests after these that will need to continue to run, just not in this class or .py file.
EDIT: So the tests in this case all depend on the prior test passing, otherwise it would fail for the same defect as the above test. However, my main dilemma is I'm not sure how to tell it to skip those tests and continue with the rest of the tests that PyTest has picked up. I looked at PyTest's skip handling and it's pretty much identical to unittest. I'm trying to avoid coding in a logic check for test failures if it's unnecessary, but it appears that may be the only solution.