PytestUnhandledThreadExceptionWarning during uiautomator dump

760 views Asked by At

In my pytest I am actually not doing much just making uiautomator dump and pull the created file to local path, but it does give me the below warning:

copporcomm_test/access_try.py::test_unconfig_deamon_is_running_android
      /usr/lib/python3/dist-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-1
...
warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))

When I remark out the line where I do uiautomator dump it doesn't occurs. Any clue what it could be the problem?

My small test case:

def test_android(adb):
    adb_output = adb.shell(command="uiautomator dump", assert_ok=True, timeout=10)
    assert "UI hierchary dumped to" in adb_output

    adb.pull(on_device_path="/sdcard/window_dump.xml", local_path="ui.xml", timeout=10)
    print("Pulled file!")

Of course I could catch the warning but I want also to understand why it happens.

After the comment from Teejay Bruno I modified the code to see the threads and I realized that from start it already has 4 thread counts. Below printout is when thread1 and thread2 lines are comment out (in the test_android()).

START: Current active thread count:  4

Updated test case using threading:

import threading
import pytest

def thread1_sub(adb):
    print("Create xml file with current activity layout.")
    adb_output = adb.shell(command="uiautomator dump", assert_ok=True, timeout=300)
    assert "UI hierchary dumped to" in adb_output

def thread2_sub(adb):
    print("Pull created xml file to loacal path.")
    adb.pull(on_device_path="/sdcard/window_dump.xml", local_path="ui.xml", timeout=10)
 
def test_android(adb):
    thread1 = threading.Thread(target=thread1_sub, args=(adb,), name="Thread1")
    thread2 = threading.Thread(target=thread2_sub, args=(adb,), name="Thread2")
    print("START: Current active thread count: ", threading.active_count())
    thread1.start()
    thread2.start()
    thread2.join()

Now by using threading everything works just fine and all threads are handled.

0

There are 0 answers