From c0b3b021dccf37b6665d35e5cfafab88f2c16618 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sun, 14 Jan 2018 19:56:47 +0000 Subject: [PATCH] Improve test resiliency Avoids occasional test executions failures caused by leftover files on dev machine or by preexisting configuration files. Change-Id: Ia0ba29e2dda58c37410a6926cae3039e4ba3473e --- .gitignore | 3 ++- jenkins_jobs/config.py | 8 ++++---- tests/base.py | 5 ++++- tox.ini | 18 +++++++++++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 55f16a11a..4a982d423 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,8 @@ etc/jenkins_jobs.ini dist/* doc/build/* jenkins_jobs/versioninfo -.coverage +.coverage* cover/ jenkins-job-builder testr_subunit_log +__pycache__ \ No newline at end of file diff --git a/jenkins_jobs/config.py b/jenkins_jobs/config.py index 95f944854..70d2018e5 100644 --- a/jenkins_jobs/config.py +++ b/jenkins_jobs/config.py @@ -199,10 +199,10 @@ class JJBConfig(object): # check the ignore_cache setting ignore_cache = False if config.has_option(self._section, 'ignore_cache'): - logging.warning("ignore_cache option should be moved to the " - "[job_builder] section in the config file, the " - "one specified in the [jenkins] section will be " - "ignored in the future") + logger.warning("ignore_cache option should be moved to the " + "[job_builder] section in the config file, the " + "one specified in the [jenkins] section will be " + "ignored in the future") ignore_cache = config.getboolean(self._section, 'ignore_cache') elif config.has_option('job_builder', 'ignore_cache'): ignore_cache = config.getboolean('job_builder', 'ignore_cache') diff --git a/tests/base.py b/tests/base.py index 06fedb28a..847714d03 100644 --- a/tests/base.py +++ b/tests/base.py @@ -100,8 +100,11 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml', conf_candidate = re.sub(r'\.yaml$|\.json$', '.conf', input_filename) conf_filename = files.get(os.path.basename(conf_candidate), None) - if conf_filename is not None: + if conf_filename: conf_filename = conf_filename[0] + else: + # for testing purposes we want to avoid using user config files + conf_filename = os.devnull scenarios.append((input_filename, { 'in_filename': input_filename, diff --git a/tox.ini b/tox.ini index 29d1c0a72..1d1f1aa01 100644 --- a/tox.ini +++ b/tox.ini @@ -5,15 +5,23 @@ skip_missing_interpreters = true [testenv] # Note(Vek): JJB is not compatible with a non-zero PYTHONHASHSEED -setenv = VIRTUAL_ENV={envdir} - SUBUNIT_FORMATTER=tee testr_subunit_log - OS_STDOUT_NOCAPTURE=False - PYTHONHASHSEED=0 +setenv = LANG=en_US.UTF-8 + PYTHONDONTWRITEBYTECODE=1 + PYTHONHASHSEED=0 + SUBUNIT_FORMATTER=tee testr_subunit_log + VIRTUAL_ENV={envdir} usedevelop = True install_command = pip install {opts} {packages} deps = -r{toxinidir}/test-requirements.txt -commands = python setup.py testr --slowest --testr-args='{posargs}' +# cleanup is needed mostly for dev environmnts and assures that if dev +# is switching branch, no lefovers will impact execution. +# No git commands here because test should run even from a source archive. +commands = + - find . -type f -name "*.pyc" -delete + - find . -type d -name "__pycache__" -delete + python setup.py testr --slowest --testr-args='{posargs}' +whitelist_externals = find [testenv:cover] commands =