Skip to content

Commit

Permalink
tests: add --coverage option
Browse files Browse the repository at this point in the history
Added --coverage option to both py.test and 'python setup.py test' that
will cause py.test to generate a coverage report after running the
tests.
  • Loading branch information
jtriley committed Feb 11, 2014
1 parent 0b585e3 commit e52b36a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -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
6 changes: 5 additions & 1 deletion setup.py
Expand Up @@ -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')

Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions starcluster/tests/conftest.py
Expand Up @@ -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):
Expand All @@ -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']

0 comments on commit e52b36a

Please sign in to comment.