0

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.

FotisK
  • 1,055
  • 2
  • 13
  • 28
  • Your `adb.shell()` command is likely starting the execution of a separate thread which does not complete before the `timeout` argument. If you'd like, you can test this by querying `threading.active_count()` before and after the call. – Teejay Bruno Feb 06 '23 at 16:40
  • Although using threading has solved the issue and all threads are handled I couldn't figure out if the timeout is too short or not. From some time measurements the dump creation costs ~3s and pull 0.05s. Many thanks – FotisK Feb 06 '23 at 21:06

0 Answers0