เมื่อรัน unittest ฉันมักจะได้รับ error: [Errno 32] Broken pipe
ดูเหมือนว่าจะเป็นข้อผิดพลาดที่ไม่เป็นอันตรายที่เกิดขึ้นระหว่างการทดสอบ แต่ฉันไม่สามารถป้องกันหรือปราบปรามได้
สิ่งที่ฉันได้ลอง ได้แก่ การเปลี่ยน SIGPIPE
การจัดการเป็น SIG_DFL
และการเรียกใช้แอปด้วย threaded=True
ถ้าฉันเป็น try/except
ฉันไม่รู้ว่าจะต้องตัดโค้ดใดเนื่องจากอยู่ในบริบทของการทดสอบแบบ Unittesting
ฉันไม่สนใจที่จะจับ/ป้องกันข้อผิดพลาดมากเท่ากับการระงับเอาต์พุตในขณะที่การทดสอบอื่นๆ ทั้งหมดทำงานเสร็จสิ้น ฉันควรลองอะไรอีก?
แก้ไข:
นี่คือตัวอย่างโค้ดบางส่วนที่บ่อยครั้งแต่ไม่ได้ส่งผลให้เกิดข้อผิดพลาดเสมอไป:
def test_register(self):
self.driver.get(self.get_server_url() + url_for(u'register'))
body = self.driver.find_element_by_id(u'body')
username_input = body.find_element_by_id(u'username')
username_input.send_keys(self.USER1_DISPLAY_USERNAME)
privacy_policy = body.find_element_by_id(u'privacy_policy')
privacy_policy.click()
#NOTE: not shown - more lines filling out form elements exactly like the above lines
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
register_button = body.find_element_by_id(u'onclick-register')
register_button.click()
และนี่คือตัวอย่างข้อความแสดงข้อผิดพลาด:
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 44668)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 599, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 657, in __init__
self.finish()
File "/usr/lib/python2.7/SocketServer.py", line 716, in finish
self.wfile.close()
File "/usr/lib/python2.7/socket.py", line 283, in close
self.flush()
File "/usr/lib/python2.7/socket.py", line 307, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------
ดูเหมือนว่าจะเกิดขึ้นเฉพาะกับการทดสอบการรวมระบบเท่านั้น ฉันใช้ Selenium และ LiveServerTestCase
โดยตั้งค่าพอร์ต LIVESERVER_PORT
เป็น 8943
การกล่าวถึงพอร์ต 44668
ในข้อความแสดงข้อผิดพลาดดูน่าสงสัย
ปัญหาของฉันฟังดูเหมือนกับ ระงับการพิมพ์เอาต์พุตใน unittests แต่ไม่มีวิธีแก้ไขปัญหาเหล่านั้นเลย