提交 abe11d5b 编写于 作者: L Lukáš Doktor

selftest: Avoid using py2 when checking py3

Some tests execute avocado directly, which uses "/usr/bin/env python" by
default. On distributions with py2 and py3 installed we might end-up
running those tests using python2 while running the main selftest by
python3.

With this change we need to make sure to pass the correct python binary
in UNITTEST_AVOCADO_CMD as it's not doing this by default (to allow any
avocado command).
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 510ca7f7
......@@ -39,7 +39,8 @@ from avocado.utils import path as utils_path
basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD", "./scripts/avocado")
AVOCADO = os.environ.get("UNITTEST_AVOCADO_CMD",
"%s ./scripts/avocado" % sys.executable)
LOCAL_IMPORT_TEST_CONTENTS = '''
from avocado import Test
......@@ -791,8 +792,9 @@ class RunnerSimpleTest(unittest.TestCase):
test_base_dir = os.path.dirname(self.pass_script.path)
os.chdir(test_base_dir)
test_file_name = os.path.basename(self.pass_script.path)
cmd_line = ('%s run --job-results-dir %s --sysinfo=off'
' "%s"' % (avocado_path, self.tmpdir, test_file_name))
cmd_line = ('%s %s run --job-results-dir %s --sysinfo=off'
' "%s"' % (sys.executable, avocado_path, self.tmpdir,
test_file_name))
result = process.run(cmd_line, ignore_status=True)
expected_rc = exit_codes.AVOCADO_ALL_OK
self.assertEqual(result.exit_status, expected_rc,
......
......@@ -10,6 +10,9 @@ basedir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
basedir = os.path.abspath(basedir)
PY_CMD = sys.executable
class StandaloneTests(unittest.TestCase):
def setUp(self):
......@@ -28,22 +31,22 @@ class StandaloneTests(unittest.TestCase):
return result
def test_passtest(self):
cmd_line = './examples/tests/passtest.py -r'
cmd_line = '%s ./examples/tests/passtest.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_ALL_OK
self.run_and_check(cmd_line, expected_rc, 'passtest')
def test_warntest(self):
cmd_line = './examples/tests/warntest.py -r'
cmd_line = '%s ./examples/tests/warntest.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_ALL_OK
self.run_and_check(cmd_line, expected_rc, 'warntest')
def test_failtest(self):
cmd_line = './examples/tests/failtest.py -r'
cmd_line = '%s ./examples/tests/failtest.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
self.run_and_check(cmd_line, expected_rc, 'failtest')
def test_errortest_nasty(self):
cmd_line = './examples/tests/errortest_nasty.py -r'
cmd_line = '%s ./examples/tests/errortest_nasty.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty')
if sys.version_info[0] == 3:
......@@ -56,14 +59,14 @@ class StandaloneTests(unittest.TestCase):
"exception details." % (exc))
def test_errortest_nasty2(self):
cmd_line = './examples/tests/errortest_nasty2.py -r'
cmd_line = '%s ./examples/tests/errortest_nasty2.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty2')
self.assertIn(b"Exception: Unable to get exception, check the traceback"
b" for details.", result.stdout)
def test_errortest_nasty3(self):
cmd_line = './examples/tests/errortest_nasty3.py -r'
cmd_line = '%s ./examples/tests/errortest_nasty3.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
result = self.run_and_check(cmd_line, expected_rc, 'errortest_nasty3')
if sys.version_info[0] == 3:
......@@ -73,7 +76,7 @@ class StandaloneTests(unittest.TestCase):
self.assertIn(exc, result.stdout)
def test_errortest(self):
cmd_line = './examples/tests/errortest.py -r'
cmd_line = '%s ./examples/tests/errortest.py -r' % PY_CMD
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
self.run_and_check(cmd_line, expected_rc, 'errortest')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册