Tests: fixing Python 3.8.1 errors on Mac.
- "Can't pickle local object ..." - "if __name__ == '__main__':" pattern required for multiprocessing
This commit is contained in:
@@ -4,6 +4,7 @@ import unittest
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ class TestProxy(TestApplicationPython):
|
|||||||
|
|
||||||
SERVER_PORT = 7999
|
SERVER_PORT = 7999
|
||||||
|
|
||||||
def run_server(self):
|
@staticmethod
|
||||||
|
def run_server(server_port):
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
|
||||||
server_address = ('', self.SERVER_PORT)
|
server_address = ('', server_port)
|
||||||
sock.bind(server_address)
|
sock.bind(server_address)
|
||||||
sock.listen(5)
|
sock.listen(5)
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ Content-Length: 10
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.run_process(self.run_server)
|
self.run_process(self.run_server, self.SERVER_PORT)
|
||||||
self.waitforsocket(self.SERVER_PORT)
|
self.waitforsocket(self.SERVER_PORT)
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
|
|||||||
@@ -209,9 +209,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
def _run_unit():
|
self._p = Process(target=subprocess.call, args=[ [
|
||||||
subprocess.call(
|
|
||||||
[
|
|
||||||
self.unitd,
|
self.unitd,
|
||||||
'--no-daemon',
|
'--no-daemon',
|
||||||
'--modules', self.pardir + '/build',
|
'--modules', self.pardir + '/build',
|
||||||
@@ -219,10 +217,7 @@ class TestUnit(unittest.TestCase):
|
|||||||
'--pid', self.testdir + '/unit.pid',
|
'--pid', self.testdir + '/unit.pid',
|
||||||
'--log', self.testdir + '/unit.log',
|
'--log', self.testdir + '/unit.log',
|
||||||
'--control', 'unix:' + self.testdir + '/control.unit.sock',
|
'--control', 'unix:' + self.testdir + '/control.unit.sock',
|
||||||
]
|
] ])
|
||||||
)
|
|
||||||
|
|
||||||
self._p = Process(target=_run_unit)
|
|
||||||
self._p.start()
|
self._p.start()
|
||||||
|
|
||||||
if not self.waitforfiles(
|
if not self.waitforfiles(
|
||||||
@@ -299,11 +294,11 @@ class TestUnit(unittest.TestCase):
|
|||||||
if found:
|
if found:
|
||||||
print('skipped.')
|
print('skipped.')
|
||||||
|
|
||||||
def run_process(self, target):
|
def run_process(self, target, *args):
|
||||||
if not hasattr(self, '_processes'):
|
if not hasattr(self, '_processes'):
|
||||||
self._processes = []
|
self._processes = []
|
||||||
|
|
||||||
process = Process(target=target)
|
process = Process(target=target, args=args)
|
||||||
process.start()
|
process.start()
|
||||||
|
|
||||||
self._processes.append(process)
|
self._processes.append(process)
|
||||||
|
|||||||
Reference in New Issue
Block a user