에서 비 시험 방법을 조롱해야합니다 myapp.apps.mytask1.views
에서난 그냥 아래와 같은 테스트 클래스가 장고
@mock.patch('myapp.apps.mytask1.views.image_processing.apply_async')
class SortAPITestCase(APITestCase):
def hit_scan("""some args"""):
scan_uri = 'some url'
data = 'some data'
resp = self.client.post(scan_uri, data=data)
id = resp.data['id']
self.assertEqual(resp.status_code, 201)
return data, id
def setUp(self):
super(SortAPITestCase, self).setUp()
self.scan_data, self.id = self.hit_scan()
def test_1(self, mock_obj):
.....
def test_2(self, mock_obj):
.....
, 스캔 API, 셀러리 작업 등을 호출 post
방법이있다 :
def post("""some args"""):
""" here there is a celery task that gets called"""
image_processing.apply_async(
args=[img_data], queue='image', countdown=10
)
셀러리 작업 인쇄 출력이 같이 다소 호출되는 메시지 아래
@shared_task
def image_processing(img_data):
if os.isfile(img_file):
print "File Not Present"
따라서 img_file
이 없으면 File Not Present
이 출력됩니다. 테스트 기능 (모의 함께)이 Scan API에 게시되면 모의로 인해이 인쇄 메시지가 콘솔에 인쇄되지 않습니다. 그러나 hit_scan()
방법을 사용하면 Scan API에 게시 할 때 셀러리 작업이 조롱을 당하지 않으므로이 메시지가 인쇄됩니다. 셀러리 작업을 조롱 할 수 있습니까? hit_scan
??
그래서 테스트를 실행할 때 콘솔에 print 문이 나타나지 않도록하는 방법이 있습니까 ??
그런데 모든 테스트 케이스가 통과합니다. 그 관점에서 아무런 문제가 없습니다. 방금 셀롤러 작업의 print 문 대신에 ....
으로 콘솔을 더보기 좋게하려고했습니다.
: 문제가 해결되었습니다. 여기 내가 무엇을 했는가
@mock.patch('myapp.apps.mytask1.views.image_processing.apply_async')
def hit_scan(self, mock_obj, """some args"""):
나는 실제'mock.patch()'로 질문을 편집했다. 'hit_scan()'이'test_' 함수에서 호출 될 때마다, 셀러 리 작업에 명령문을 출력하지 않습니다. 나는 그것을 확인했습니다 .. –
당신이 언급 한 것은 문제가 아닙니다. 당신은 내 편집 된 질문을 보았기를 바랍니다. 감사합니다 –
고마워 ... 내가 문제를 해결. 편집 확인 –