我正在尝试在运行线程后从python中运行pytest, 这是一个简单的案例:
============================= 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
但是pytest一直挂着。这就是输出的样子:
cell.accessoryView = UIImageView(image:UIImage(named:"imageNmae")!)
它就像这样挂起,直到我强行退出它。 有没有办法让这项工作?
答案 0 :(得分:1)
要提两件事:
让我们说:
<强> file.py 强>
import time
import threading
class A(object):
def __init__(self):
self._thread_a = threading.Thread(target=self.do_a)
self._thread_a.daemon = True
self._thread_a.start()
def do_a(self):
print "a"
time.sleep(2)
self.do_a()
def stop(self, timeout):
self._thread_a.join(timeout)
<强> test_file.py 强>
import pytest
from .file import A
@pytest.fixture()
def a():
return A()
def test_sth(a):
a.start()
print('I can do sth else')
a.stop(timeout=1)