I am trying to run pytest from within python after running a thread, here is a simple example of the case:
import time
import threading
import pytest
class A(object):
def __init__(self):
self._thread_a = threading.Thread(target=self.do_a)
self._thread_a.start()
pytest.main()
def do_a(self):
print "a"
time.sleep(2)
self.do_a()
if __name__ == "__main__":
a = A()
but pytest keeps hanging. this is what the output looks like:
============================= test session starts ==============================
platform darwin -- Python 2.7.10, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
metadata: {'Python': '2.7.10', 'Platform': 'Darwin-17.3.0-x86_64-i386-64bit', 'Packages': {'py': '1.5.2', 'pytest': '3.3.2', 'pluggy': '0.6.0'}, 'Plugins': {'session2file': '0.1.9', 'celery': '4.0.0','html': '1.16.1', 'metadata': '1.5.1'}}
rootdir: /Users/path/to/root/dir, inifile:
plugins: session2file-0.1.9, metadata-1.5.1, html-1.16.1, celery-4.0.0
and it just hangs like this until I force quit it. is there any way to make this work?
since you started a thread that basically is a endless recursion,
python itself will hang waiting for it to exit
this can be elevated by declaring it a daemon thread (python doesn't wait on those)
Closing as this has not seen activity in awhile.
To me it looked like pytest would not run at all (hanging before collecting), but it actually does.
So all is fine I guess.
Most helpful comment
since you started a thread that basically is a endless recursion,
python itself will hang waiting for it to exit
this can be elevated by declaring it a daemon thread (python doesn't wait on those)