Skip to content

Commit 1b2fb82

Browse files
committed
Test runner fixes
- Require running it with Python 3. We want to run tests with new RF versions that aren't compatible with Python 2 even though remote server itself still supports Python 2. - Make compatible with RF 4.0+ that don't have criticality concept anymore.
1 parent bb44b3d commit 1b2fb82

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

test/run.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
"""Script for running the remote server tests using different interpreters.
44
5-
Usage: run.py interpreter [arguments]
5+
Usage: run.py [interpreter] [arguments]
66
7-
`interpreter` is the only required argument and specifies Python interpreter
8-
to run the remote server with. The interpreter must be found from PATH or
9-
given as an absolute path.
7+
`interpreter` is name or path of the Python interpreter to run the remote
8+
server with. The interpreter must be found from PATH or given as an absolute
9+
path. If not given, `python` will be used by default.
1010
1111
`arguments` are normal Robot Framework options and arguments. Test case files
12-
are under `atest` directory.
12+
are under the `atest` directory.
1313
14-
If only the interpreter are given, all acceptance tests under `atest` directory
14+
If no arguments are given, all acceptance tests under the `atest` directory
1515
as well as unit tests under `utest` are executed. Unit tests are run first
16-
and acceptance tests skipped if they fail. To run only unit tests, use
17-
`utest/run.py` instead.
16+
and acceptance tests skipped if they fail.
1817
19-
Examples:
18+
If arguments are given, unit tests are not run. To run only unit tests, use
19+
`test/utest/run.py` instead.
20+
21+
This script must be run using Python 3.
2022
21-
run.py python # All unit and acceptance tests with Python
23+
Examples:
24+
run.py # All unit and acceptance tests with Python
2225
run.py "py -3" atest/kwargs.robot # One suite with Python 3 on Windows
2326
run.py ipy --test NoMessage atest # Specific test using IronPython
2427
"""
2528

26-
from __future__ import print_function
27-
2829
from os.path import abspath, dirname, exists, join
2930
import os
3031
import shutil
@@ -36,26 +37,30 @@
3637
import robotstatuschecker
3738

3839

39-
if len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv:
40+
if '-h' in sys.argv or '--help' in sys.argv:
4041
sys.exit(__doc__)
4142

4243
curdir = dirname(abspath(__file__))
4344
results = join(curdir, 'results')
4445
output = join(results, 'output.xml')
45-
interpreter = sys.argv[1]
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)
49+
py2 = version.split()[1][:3] == '2.7'
4650
arguments = sys.argv[2:]
4751

4852
if exists(results):
4953
shutil.rmtree(results)
5054
os.mkdir(results)
5155

5256
if not arguments:
53-
print('Running unit tests with "%s".' % interpreter)
57+
print(f'Running unit tests with "{interpreter}".')
5458
command = shlex.split(interpreter) + [join(curdir, 'utest', 'run.py')]
5559
rc = subprocess.call(command)
5660
print()
5761
if rc != 0:
58-
print('%d unit test%s failed.' % (rc, 's' if rc != 1 else ''))
62+
tests = 'tests' if rc != 1 else 'test'
63+
print(f'{rc} unit {tests} failed.')
5964
sys.exit(rc)
6065
arguments = [join(curdir, 'atest')]
6166

@@ -66,12 +71,13 @@
6671
excludes.extend(['--exclude', 'no-ipy'])
6772
command = [
6873
'python', '-m', 'robot.run',
69-
'--variable', 'INTERPRETER:%s' % interpreter,
70-
'--doc', 'Remote server tests on "%s"' % interpreter,
71-
'--metadata', 'Server_Interpreter:%s' % interpreter,
74+
'--variable', f'INTERPRETER:{interpreter}',
75+
'--variable', f'PY2:{py2}',
76+
'--doc', f"Remote server tests using '{interpreter}'.",
77+
'--metadata', f'Interpreter Version:{version}',
7278
'--output', output, '--log', 'NONE', '--report', 'NONE'
7379
] + excludes + arguments
74-
print('Running acceptance tests with command:\n%s' % ' '.join(command))
80+
print('Running acceptance tests with command:\n' + ' '.join(command))
7581
rc = subprocess.call(command)
7682
print()
7783
if rc > 250:
@@ -80,10 +86,11 @@
8086

8187
print('Verifying results.')
8288
robotstatuschecker.process_output(output)
83-
rc = robot.rebot(output, outputdir=results, noncritical='skip')
89+
rc = robot.rebot(output, outputdir=results)
8490
print()
8591
if rc == 0:
8692
print('All tests passed.')
8793
else:
88-
print('%d acceptance test%s failed.' % (rc, 's' if rc != 1 else ''))
94+
tests = 'tests' if rc != 1 else 'test'
95+
print(f'{rc} acceptance {tests} failed.')
8996
sys.exit(rc)

0 commit comments

Comments
 (0)