提交 f397693e 编写于 作者: L Lukáš Doktor 提交者: Amador Pahim

teststmpdir: Use variable to share env variable name

The "AVOCADO_TESTS_COMMON_TMPDIR" is an environmental variable name used
to store the location of a common tmpdir. To avoid issues with
typos/name changes let's use the variable in `avocado.core.test` to
share the env variable name everywhere.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 6eccf580
......@@ -47,6 +47,11 @@ else:
import unittest
#: Environment variable used to store the location of a tmpfile which is
#: preserved across all tests execution (usually in one job)
COMMON_TMPDIR_NAME = 'AVOCADO_TESTS_COMMON_TMPDIR'
class NameNotTestNameError(Exception):
"""
......@@ -286,7 +291,7 @@ class Test(unittest.TestCase):
Returns the path of the temporary directory that will stay the
same for all tests in a given Job.
"""
env_var = 'AVOCADO_TESTS_COMMON_TMPDIR'
env_var = COMMON_TMPDIR_NAME
path = os.environ.get(env_var)
if path is None:
msg = 'Environment Variable %s is not set.' % env_var
......
......@@ -20,6 +20,7 @@ import shutil
import tempfile
from avocado.core.plugin_interfaces import JobPre, JobPost
from avocado.core import test
class TestsTmpDir(JobPre, JobPost):
......@@ -28,7 +29,7 @@ class TestsTmpDir(JobPre, JobPost):
description = 'Creates a temporary directory for tests consumption'
def __init__(self):
self._varname = 'AVOCADO_TESTS_COMMON_TMPDIR'
self._varname = test.COMMON_TMPDIR_NAME
self._dirname = None
def pre(self, job):
......
......@@ -11,6 +11,7 @@ else:
import unittest
from avocado.core import exit_codes
from avocado.core import test
from avocado.utils import process
from avocado.utils import script
......@@ -32,14 +33,14 @@ class MyTest(Test):
"""
SIMPLE_SCRIPT = """#!/bin/bash
mktemp ${AVOCADO_TESTS_COMMON_TMPDIR}/XXXXXX
if [ $(ls ${AVOCADO_TESTS_COMMON_TMPDIR} | wc -l) == 1 ]
mktemp ${{{0}}}/XXXXXX
if [ $(ls ${{{0}}} | wc -l) == 1 ]
then
exit 0
else
exit 1
fi
"""
""".format(test.COMMON_TMPDIR_NAME)
class TestsTmpDirTests(unittest.TestCase):
......@@ -63,6 +64,9 @@ class TestsTmpDirTests(unittest.TestCase):
"%d:\n%s" % (cmd_line, expected_rc, result))
return result
@unittest.skipIf(test.COMMON_TMPDIR_NAME in os.environ,
"%s already set in os.environ"
% test.COMMON_TMPDIR_NAME)
def test_tests_tmp_dir(self):
cmd_line = ("./scripts/avocado run --sysinfo=off "
"--job-results-dir %s %s %s" %
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册