diff --git a/.travis.yml b/.travis.yml index f2ec8adba..1c1673a68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ python: - 2.6 - 2.7 install: - - python setup.py install -q + - python setup.py install --quiet script: - - python setup.py test + - python setup.py test --coverage notifications: irc: channels: "irc.freenode.org#starcluster" diff --git a/requirements.txt b/requirements.txt index c7f04afbe..97773ba22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,6 @@ pep8==1.4.6 pyflakes==0.7.3 watchdog==0.7.1 pytest==2.5.2 +pytest-cov==1.6 sphinx==1.2.1 pudb==2013.5.1 diff --git a/setup.py b/setup.py index f864b5fe8..8210192d6 100644 --- a/setup.py +++ b/setup.py @@ -32,16 +32,20 @@ class PyTest(TestCommand): user_options = TestCommand.user_options[:] user_options += [ ('live', 'L', 'Run live StarCluster tests on a real AWS account'), + ('coverage', 'C', 'Produce a coverage report for StarCluster'), ] def initialize_options(self): TestCommand.initialize_options(self) self.live = None + self.coverage = None def finalize_options(self): TestCommand.finalize_options(self) self.test_suite = True self.test_args = [] + if self.coverage: + self.test_args.append('--coverage') if self.live: self.test_args.append('--live') @@ -53,7 +57,7 @@ def run_tests(self): console_scripts = ['starcluster = starcluster.cli:main'] extra = dict(test_suite="starcluster.tests", - tests_require="pytest", + tests_require=["pytest", "pytest-cov"], cmdclass={"test": PyTest}, install_requires=["paramiko>=1.12.1", "boto>=2.23.0", "workerpool>=0.9.2", "Jinja2>=2.7", diff --git a/starcluster/tests/conftest.py b/starcluster/tests/conftest.py index fce8082c1..3b8380a91 100644 --- a/starcluster/tests/conftest.py +++ b/starcluster/tests/conftest.py @@ -4,6 +4,8 @@ def pytest_addoption(parser): parser.addoption("-L", "--live", action="store_true", default=False, help="Run live StarCluster tests on a real AWS account") + parser.addoption("-C", "--coverage", action="store_true", default=False, + help="Produce a coverage report for StarCluster") def pytest_runtest_setup(item): @@ -15,3 +17,6 @@ def pytest_configure(config): config.option.exitfirst = True config.option.verbose = True config.option.capture = 'no' + if config.getoption("--coverage"): + config.option.cov_source = ['starcluster'] + config.option.cov_report = ['term-missing']