Running Python Test Suite with TestRunner getting WebDriverException

New to appium and I am trying to run concurrent test cases using testrunner. It will run the first test and on the 2nd test it throws this error:

WebDriverException: Message: A new session could not be created. Details: Problem getting session data for driver type AndroidDriver; does it implement ‘get driverData’?

I know this means the last appium session did not close, I just don’t know why. Here is my setup method:

class DriverBuilderAndroid(object):

def setUp(self):
    "Setup for the test"
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '6.0.1'
    desired_caps['deviceName'] = '05157df532e5e40e'
    # Returns abs path relative to this file and not cwd
    desired_caps['app'] = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '/Users/tyler/Desktop/Instasize apk/InstaSize_R9_Test_3_7_6_107_collage_crash_fix_3.apk'))
    desired_caps['appPackage'] = 'com.jsdev.instasize'
    desired_caps['appActivity'] = '.activities.MainActivity'
    self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    self.driver.implicitly_wait(10)

def __init__(self):
    self.setUp()

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

Here is my test script:

class CoastFilterExportTest(unittest.TestCase):
 # Class to run tests on exporting photos to Instagram


def test_filter_uploads(self):
    driver_builder = DriverBuilderAndroid()
    driver = driver_builder.driver

    # taps on the + icon
    addPhoto = GridPage(driver)
    addPhoto.addPhotoTap()

    # Asserts collapseIcon is displayed
    collapseIcon = GridPage(driver)
    collapseIcon.collapseIconFind()

    # taps on the native photos container
    tapPhotoContainer = GridPage(driver)
    tapPhotoContainer.photoContainers()

    # Asserts allPhotosButton is displayed
    allPhotosButton = PhotoLibraryAsserts(driver)
    allPhotosButton.allPhotosButton()

    # taps on the top left photo
    tapTopLeftPhoto = GridPage(driver)
    tapTopLeftPhoto.topLeftPhoto()

    # Searches for the Review Popup and dismisses it
    dismissReviewPopup = TryExcepts(driver)
    dismissReviewPopup.reviewPopup()

    # taps on the filter
    filters = EditorPage(driver)
    filters.coastFilter()

    # Asserts tvFilterLevel is displayed
    tvFilterLevel = PhotoLibraryAsserts(driver)
    tvFilterLevel.tvFilterLevel()


    # taps on share button
    tapShareButton = EditorPage(driver)
    tapShareButton.sharebutton()

    # Taps on Instagram icon
    tapInstagram = GridPage(driver)
    tapInstagram.instagramIcon()

    # Searches for Instagram android popup on bottom of screen
    instagramSystemPopup = TryExcepts(driver)
    instagramSystemPopup.instagramSystemPopup()

    sleep(5)
    driver.back()

    # Asserts the + button is displayed
    addPhoto = GridPage(driver)
    addPhoto.addPhotoFind()

    driver.tearDown()


# ---START OF SCRIPT
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(CoastFilterExportTest)
unittest.TextTestRunner(verbosity=2).run(suite)

and here is my testRunner suite:

coastFilter = unittest.TestLoader().loadTestsFromTestCase(CoastFilterTestCase)
athensFilter = unittest.TestLoader().loadTestsFromTestCase(AthensFilterExportTest)

test_suite = unittest.TestSuite([coastFilter, athensFilter])

unittest.TextTestRunner(verbosity=2).run(test_suite)

Has anyone else run into this issue before? Do I need to format my test suite differently? I appreciate any help I can get. Thank you. I have tried adding different commands at the end of the first test such as driver.quit() and none have worked.

can you remove this code and try

Also there are few sample scripts here, check if you haven’t

https://github.com/appium/sample-code/tree/master/sample-code/examples/python

Thank you for your help and the sample code. I was able to fix it. Apparently the next test case was trying to start before the teardown method had completed from the previous test. My solution was to run all the test scripts using a bash script with a sleep timer between each script. This is much faster than using testrunner.