Fix un-assignment local variable 'returncode' error
This commit fixes an error "local variable 'returncode' referenced
before assignment" when we run 'tempest run' with having a
testrepository.
Change-Id: I99425de8481db4bddbe06b715bcceaaadaa1a797
diff --git a/tempest/cmd/run.py b/tempest/cmd/run.py
index e78f6b0..26bd418 100644
--- a/tempest/cmd/run.py
+++ b/tempest/cmd/run.py
@@ -70,6 +70,7 @@
def take_action(self, parsed_args):
self._set_env()
+ returncode = 0
# Local execution mode
if os.path.isfile('.testr.conf'):
# If you're running in local execution mode and there is not a
@@ -77,8 +78,8 @@
if not os.path.isdir('.testrepository'):
returncode = run_argv(['testr', 'init'], sys.stdin, sys.stdout,
sys.stderr)
- if returncode:
- sys.exit(returncode)
+ if returncode:
+ sys.exit(returncode)
else:
print("No .testr.conf file was found for local execution")
sys.exit(2)
diff --git a/tempest/tests/cmd/test_run.py b/tempest/tests/cmd/test_run.py
index 9aa06e5..dcffd21 100644
--- a/tempest/tests/cmd/test_run.py
+++ b/tempest/tests/cmd/test_run.py
@@ -102,6 +102,14 @@
subprocess.call(['git', 'init'], stderr=DEVNULL)
self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
+ def test_tempest_run_passes_with_testrepository(self):
+ # Git init is required for the pbr testr command. pbr requires a git
+ # version or an sdist to work. so make the test directory a git repo
+ # too.
+ subprocess.call(['git', 'init'], stderr=DEVNULL)
+ subprocess.call(['testr', 'init'])
+ self.assertRunExit(['tempest', 'run', '--regex', 'passing'], 0)
+
def test_tempest_run_fails(self):
# Git init is required for the pbr testr command. pbr requires a git
# version or an sdist to work. so make the test directory a git repo