diff --git a/jenkins_jobs/cmd.py b/jenkins_jobs/cmd.py index e60376c67..097c8484b 100755 --- a/jenkins_jobs/cmd.py +++ b/jenkins_jobs/cmd.py @@ -118,12 +118,12 @@ def setup_config_settings(options): config = ConfigParser.ConfigParser() ## Load default config always config.readfp(cStringIO.StringIO(DEFAULT_CONF)) - if options.command == 'test': - logger.debug("Not reading config for test output generation") - elif os.path.isfile(conf): + if os.path.isfile(conf): logger.debug("Reading config from {0}".format(conf)) conffp = open(conf, 'r') config.readfp(conffp) + elif options.command == 'test': + logger.debug("Not requiring config for test output generation") else: raise JenkinsJobsException( "A valid configuration file is required when not run as a test" diff --git a/tests/cmd/fixtures/cmd-001.conf b/tests/cmd/fixtures/cmd-001.conf new file mode 100644 index 000000000..23576d640 --- /dev/null +++ b/tests/cmd/fixtures/cmd-001.conf @@ -0,0 +1,2 @@ +[jenkins] +url=http://test-jenkins.with.non.default.url:8080/ diff --git a/tests/cmd/test_cmd.py b/tests/cmd/test_cmd.py index c3ee20459..e243796e9 100644 --- a/tests/cmd/test_cmd.py +++ b/tests/cmd/test_cmd.py @@ -83,3 +83,18 @@ class CmdTests(testtools.TestCase): 'r', 'utf-8').read() self.assertEqual(console_out.getvalue(), xml_content) + + def test_config_with_test(self): + """ + Run test mode and pass a config file + """ + args = self.parser.parse_args(['--conf', + os.path.join(self.fixtures_path, + 'cmd-001.conf'), + 'test', + os.path.join(self.fixtures_path, + 'cmd-001.yaml'), + 'foo-job']) + config = cmd.setup_config_settings(args) + self.assertEqual(config.get('jenkins', 'url'), + "http://test-jenkins.with.non.default.url:8080/")