Skip to content

Commit 30a510b

Browse files
committed
Test tuning.
- Longer timeouts avoid problems with slow interpreters (especially Jython on Windows). - Verbose unit test run to see where tests possibly hang. - Skip hanging tests with IronPython. - Support interpreter having spaces like `py -3.8`. - Cleanup (TRY/EXCEPT and IF/ELSE FTW!).
1 parent 646a094 commit 30a510b

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

test/atest/resource.robot

+15-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Library Collections
55

66
*** Variables ***
77
${INTERPRETER} python
8-
${SERVER TIMEOUT} 10 seconds
8+
${SERVER TIMEOUT} 30 seconds
99

1010
*** Keywords ***
1111
Start And Import Remote Library
@@ -18,23 +18,20 @@ Start And Import Remote Library
1818

1919
Start Remote Library
2020
[Arguments] ${library} ${port}=0 ${args}=@{EMPTY}
21-
${library} = Normalize Path ${CURDIR}/../libs/${library}
22-
${port file} = Normalize Path ${CURDIR}/../results/server_port.txt
23-
${output} = Normalize Path ${CURDIR}/../results/server_output.txt
2421
@{interpreter} = Split Command Line ${INTERPRETER}
22+
${library} = Normalize Path ${CURDIR}/../libs/${library}
23+
${port file} = Normalize Path ${CURDIR}/../results/server_port.txt
24+
${output} = Normalize Path ${CURDIR}/../results/server_output.txt
2525
Start Process @{interpreter} ${library} ${port} ${port file}
2626
... @{args} alias=${library} stdout=${output} stderr=STDOUT
27-
${status} ${result} = Run Keyword And Ignore Error
28-
... Read Port File ${port file}
29-
Return From Keyword If "${status}" == "PASS" ${result}
30-
${result} = Wait For Process timeout=10s on_timeout=terminate
31-
Fail Starting remote server failed:\n${result.stdout}
32-
33-
Read Port File
34-
[Arguments] ${path}
35-
Wait Until Created ${path} timeout=${SERVER TIMEOUT}
36-
Run Keyword And Return Get File ${path}
37-
[Teardown] Remove File ${path}
27+
TRY
28+
Wait Until Created ${port file} timeout=${SERVER TIMEOUT}
29+
EXCEPT
30+
${result} = Wait For Process timeout=10s on_timeout=terminate
31+
Fail Starting remote server failed:\n${result.stdout}
32+
END
33+
${port} = Get File ${port file}
34+
RETURN ${port}
3835

3936
Set Pythonpath
4037
${src} = Normalize Path ${CURDIR}/../../src
@@ -53,6 +50,7 @@ Server Should Be Stopped And Correct Messages Logged
5350
${expected} = Catenate SEPARATOR=\n
5451
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} started.
5552
... Robot Framework remote server at 127.0.0.1:${ACTIVE PORT} stopped.
56-
Run Keyword If ${test logging}
57-
... Should Be Equal ${result.stdout} ${expected}
53+
IF ${test logging}
54+
Should Be Equal ${result.stdout} ${expected}
55+
END
5856
Should Be Equal ${result.rc} ${0}

test/libs/KeywordDecorator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class KeywordDecorator(object):
77
def _this_name_doesnt_matter(self, arg):
88
assert arg == 'arg'
99

10-
@keyword('Result of ${expression} should be ${result:\d+}')
10+
@keyword(r'Result of ${expression} should be ${result:\d+}')
1111
def calculate(self, expression, expected):
1212
assert eval(expression) == int(expected)
1313

test/run.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@
4343
curdir = dirname(abspath(__file__))
4444
results = join(curdir, 'results')
4545
output = join(results, 'output.xml')
46-
interpreter = sys.argv[1] if len(sys.argv) > 1 else 'python'
47-
version = subprocess.check_output([interpreter, '-V'], encoding='UTF-8',
48-
stderr=subprocess.STDOUT)
46+
interpreter = shlex.split(sys.argv[1] if len(sys.argv) > 1 else 'python')
47+
version = subprocess.check_output(interpreter + ['-V'], encoding='UTF-8',
48+
stderr=subprocess.STDOUT).strip()
4949
py2 = version.split()[1][:3] == '2.7'
5050
arguments = sys.argv[2:]
5151

5252
if exists(results):
5353
shutil.rmtree(results)
5454
os.mkdir(results)
5555

56+
print(f'Running tests on {version}.\n')
57+
5658
if not arguments:
57-
print(f'Running unit tests with "{interpreter}".')
58-
command = shlex.split(interpreter) + [join(curdir, 'utest', 'run.py')]
59+
command = interpreter + [join(curdir, 'utest', 'run.py')]
60+
print('Running unit tests:\n' + ' '.join(command))
5961
rc = subprocess.call(command)
6062
print()
6163
if rc != 0:
@@ -67,17 +69,16 @@
6769
excludes = []
6870
if os.sep == '\\':
6971
excludes.extend(['--exclude', 'no-windows'])
70-
if 'ipy' in interpreter:
72+
if 'ipy' in interpreter[0]:
7173
excludes.extend(['--exclude', 'no-ipy'])
7274
command = [
7375
'python', '-m', 'robot.run',
74-
'--variable', f'INTERPRETER:{interpreter}',
76+
'--variable', f'INTERPRETER:{subprocess.list2cmdline(interpreter)}',
7577
'--variable', f'PY2:{py2}',
76-
'--doc', f"Remote server tests using '{interpreter}'.",
77-
'--metadata', f'Interpreter Version:{version}',
78+
'--metadata', f'Interpreter:{version}',
7879
'--output', output, '--log', 'NONE', '--report', 'NONE'
7980
] + excludes + arguments
80-
print('Running acceptance tests with command:\n' + ' '.join(command))
81+
print('Running acceptance tests:\n' + ' '.join(command))
8182
rc = subprocess.call(command)
8283
print()
8384
if rc > 250:

test/utest/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
test_files = [f[:-3] for f in os.listdir(curdir)
1414
if f.startswith('test_') and f.endswith('.py')]
1515
suite = unittest.defaultTestLoader.loadTestsFromNames(test_files)
16-
runner = unittest.TextTestRunner()
16+
runner = unittest.TextTestRunner(verbosity=2)
1717
result = runner.run(suite)
1818
rc = len(result.failures) + len(result.errors)
1919
sys.exit(rc)

test/utest/test_serve.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def kw(self):
1717
return 42
1818

1919

20+
@unittest.skipIf(sys.platform == 'cli', 'Tests hang on IronPython')
2021
class TestServeAndStop(unittest.TestCase):
2122

2223
def setUp(self):

0 commit comments

Comments
 (0)