In an Django application that I freshly created, where I changed it to use PostgreSQL and I created one app, I have the following test:
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class TestWebBrowser(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.webdriver = webdriver.Chrome()
cls.webdriver.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.webdriver.close()
cls.webdriver.quit()
super().tearDownClass()
def setUp(self):
self.admin = User.objects.create_superuser(username="username", password="password",
email="example@example.com")
def test_log_in(self):
self.webdriver.get(f"{self.live_server_url}/admin")
self.webdriver.find_element_by_id("id_username").send_keys("username")
self.webdriver.find_element_by_id("id_password").send_keys("password")
self.webdriver.find_element_by_id("id_password").send_keys(Keys.RETURN)
self.webdriver.find_element_by_link_text("Users").click()
The test always runs, Chrome starts, does what the test say, but at the end, sometimes it throws this error:
Exception happened during processing of request from ('127.0.0.1', 55283)
Traceback (most recent call last):
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 717, in __init__
self.handle()
File "C:\Users\pupeno\Temporary\untitled\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
All tests pass. I just get that to STDERR
. Any ideas why? Am I missing some tearing-down?
If I change tearDownClass
to:
@classmethod
def tearDownClass(cls):
cls.webdriver.quit()
I get the same error with the same frequency (as far as I can observe, without having measured it).
I'm running:
Django==2.1.2
selenium==3.141.0
and
> chromedriver.exe --version
ChromeDriver 2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a)
and
Google Chrome Version 70.0.3538.102 (Official Build) (64-bit)
The full output of running the tests look like this:
Testing started at 15:33 ...
C:\Users\pupeno\Temporary\untitled\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm 2018.2.4\helpers\pycharm\django_test_manage.py" test foo.tests.TestImportCRMData C:\Users\pupeno\Temporary\untitled
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49825)
Traceback (most recent call last):
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 647, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socketserver.py", line 717, in __init__
self.handle()
File "C:\Users\pupeno\Temporary\untitled\venv\lib\site-packages\django\core\servers\basehttp.py", line 139, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:\Users\pupeno\scoop\apps\python\current\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Destroying test database for alias 'default'...
Process finished with exit code 0