Skip to content

Commit a055ece

Browse files
fixed and improved test logic and process handling in test/remote/
--HG-- branch : dev
1 parent 070fb66 commit a055ece

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

test/remote/conftest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import sys
2+
from six import PY2
23
from textwrap import dedent
34
from subprocess import Popen
45

6+
from robot.errors import DataError
7+
58
from robottools import TestRobot
6-
from robottools.remote import RemoteRobot
79

810
import pytest
911

@@ -24,7 +26,8 @@ def process(request):
2426
"""Creates an external python process with a ``RemoteRobot`` instance
2527
loading all libraries defined in ``REMOTE_LIBRARIES``.
2628
"""
27-
return Popen([
29+
# robotremoteserver is not PY3-compatible yet
30+
return PY2 and Popen([
2831
sys.executable, '-c', dedent("""
2932
__import__('robottools.remote').remote.RemoteRobot(
3033
[%s], allow_import=[%s]
@@ -38,6 +41,14 @@ def robot_Remote(request):
3841
which automatically connects to the external ``RemoteRobot`` instance
3942
created in ``process`` fixture.
4043
"""
41-
robot = TestRobot('Test')
42-
robot.Import('Remote')
43-
return robot
44+
# make 3 connection attempts before bailing out
45+
for _ in range(3):
46+
try:
47+
# BuiltIn will also be served by RemoteRobot
48+
robot = TestRobot('Test', BuiltIn=False)
49+
robot.Import('Remote')
50+
return robot
51+
52+
except DataError:
53+
continue
54+
raise

test/remote/test_remote.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from six import text_type as unicode
1+
from six import PY3, text_type as unicode
22
from time import sleep
33

44
from decorator import decorate
5+
from moretools import isstring
56

67
from robottools import TestRobot
78

@@ -14,6 +15,11 @@ def check_process(func):
1415
which is passed to every test method as ``process`` fixture.
1516
"""
1617
def caller(func, self, process, *args, **kwargs):
18+
cls = type(self)
19+
# ensure that process was not recreated for some reason
20+
if hasattr(cls, 'process'):
21+
assert process is cls.process
22+
cls.process = process
1723
# polling returns None as long as process is running
1824
assert process.poll() is None, \
1925
"RemoteRobot process is not running (anymore)."
@@ -57,7 +63,10 @@ def test_bytes_result(self, process, robot_Remote):
5763
def test_string_result(self, process, robot_Remote):
5864
for value in [1, 2.3, 'four', u'five']:
5965
result = robot_Remote.ConvertToString(value)
60-
assert isinstance(result, unicode)
66+
# not consistent in current PY2-only robotremoteserver
67+
# (can be str or unicode):
68+
# assert isinstance(result, unicode)
69+
assert isstring(result)
6170
assert result == unicode(value)
6271

6372
@check_process
@@ -74,3 +83,16 @@ def test_StopRemoteServer(self, process, robot_Remote):
7483
process.wait()
7584
# polling returns None as long as process is running
7685
assert process.poll() is not None
86+
87+
@classmethod
88+
def teardown_class(cls):
89+
"""Ensures that the ``RemoteRobot`` process
90+
is really terminated in the end.
91+
"""
92+
if not cls.process.poll():
93+
cls.process.terminate()
94+
95+
96+
if PY3:
97+
# robotremoteserver is not PY3-compatible yet
98+
del TestRemoteRobot

0 commit comments

Comments
 (0)