From 2e2245c78301ec390601e5bd3b347a3703077be8 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Sun, 18 May 2014 18:43:58 +1200 Subject: Make setUp fail if sdist fails. Hygiene - fail at the point of failure, not later. Change-Id: Id0328f1afad5dd2fb4f5ef22e025d60eef1d4e52 --- pbr/tests/base.py | 11 +++++++---- pbr/tests/test_packaging.py | 9 +++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pbr/tests/base.py b/pbr/tests/base.py index 6c31bc9..c58414e 100644 --- a/pbr/tests/base.py +++ b/pbr/tests/base.py @@ -116,17 +116,20 @@ class BaseTestCase(testtools.TestCase, testresources.ResourcedTestCase): k.startswith('pbr_testpackage.')): del sys.modules[k] - def run_setup(self, *args): - return self._run_cmd(sys.executable, ('setup.py',) + args) + def run_setup(self, *args, **kwargs): + return self._run_cmd(sys.executable, ('setup.py',) + args, **kwargs) - def _run_cmd(self, cmd, args=[]): + def _run_cmd(self, cmd, args=[], allow_fail=True): """Run a command in the root of the test working copy. Runs a command, with the given argument list, in the root of the test working copy--returns the stdout and stderr streams and the exit code from the subprocess. """ - return _run_cmd([cmd] + list(args), cwd=self.package_dir) + result = _run_cmd([cmd] + list(args), cwd=self.package_dir) + if result[2] and not allow_fail: + raise Exception("Command failed retcode=%s" % result[2]) + return result def _run_cmd(args, cwd): diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py index abcc68d..46dd0d5 100644 --- a/pbr/tests/test_packaging.py +++ b/pbr/tests/test_packaging.py @@ -78,8 +78,7 @@ class TestPackagingInGitRepoWithCommit(base.BaseTestCase): super(TestPackagingInGitRepoWithCommit, self).setUp() repo = self.useFixture(TestRepo(self.package_dir)) repo.commit() - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # One commit, something should be in the authors list @@ -99,8 +98,7 @@ class TestPackagingInGitRepoWithoutCommit(base.BaseTestCase): def setUp(self): super(TestPackagingInGitRepoWithoutCommit, self).setUp() self.useFixture(TestRepo(self.package_dir)) - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # No commits, no authors in list @@ -119,8 +117,7 @@ class TestPackagingInPlainDirectory(base.BaseTestCase): def setUp(self): super(TestPackagingInPlainDirectory, self).setUp() - self.run_setup('sdist') - return + self.run_setup('sdist', allow_fail=False) def test_authors(self): # Not a git repo, no AUTHORS file created -- cgit v1.2.1