I am learning TDD by the "Obey the testing goat book", but I am trying to do it with Django 3.
If anyone knows it, I am at Chapter 6.
My code is:
class VisitorTest(LiveServerTestCase):
def setUp(self):
self.browser = webdriver.Chrome()
self.browser.implicitly_wait(2)
def tearDown(self):
self.browser.quit()
def test_starting(self):
print(self.live_server_url)
self.browser.get(self.live_server_url)
and in console I am getting
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
DevTools listening on ws://127.0.0.1:52187/devtools/browser/e9a03a04-819e-40a3-a0e4-bd4133d8f6cb
http://localhost:52180
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52204)
----------------------------------------
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 52202)
Exception happened during processing of request from ('127.0.0.1', 52203)
Traceback (most recent call last):
Traceback (most recent call last):
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
Traceback (most recent call last):
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 172, in handle
self.handle_one_request()
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 172, in handle
self.handle_one_request()
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
----------------------------------------
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
self.handle_one_request()
File "C:\Users\Alex\PycharmProjects\goat\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\Alex\AppData\Local\Programs\Python\Python36\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
.
----------------------------------------------------------------------
Ran 1 test in 8.779s
OK
Destroying test database for alias 'default'...
However tests are running well (I didn`t displayed them here).
I made a research but didn`t found anything conclusive
Any idea why is displaying those and how to fix them?
I've tried different suggested solutions unsuccessfully:
self.browser.refresh()
before calling quit()
(as the book itself suggest)If we look deeper this kind of errors is handled by LiveServerTestCase.server_thread.httpd.handle_error
function which default implementation in socketserver.BaseServer
just prints error messages to stderr
. As these messages are harmless I've decided to suppress them.
import sys
from contextlib import contextmanager
@contextmanager
def suppress_stderr():
"Temporarly suppress writes to stderr"
class Null:
write = lambda *args: None
err, sys.stderr = sys.stderr, Null
try:
yield
finally:
sys.stderr = err
# Suppress stderr messages during quit process
with suppress_stderr():
self.browser.quit()
This error message...
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
...implies that the connection between the ChromeDriver and the Browsing Context i.e. Chrome Browser session was closed intermittemtly.
This issue is observed when incompatibility between the version of the binaries you are using.
Ensure that:
@Test
as non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.You can finda couple of relevant discussions in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With